Skip to content
Snippets Groups Projects
Commit f65844b7 authored by Thorbjørn Lindeijer's avatar Thorbjørn Lindeijer
Browse files

Attempt to resolve a help id even when showing a diagnostic error

Makes context sensitive help work for valid expressions that happen to
be part of a marked diagnostic error. However, for now you still can't
get documentation for expressions that don't resolve.

Also, context sensitive help now also works for includes where possible.
parent 4b24de28
No related branches found
No related tags found
No related merge requests found
...@@ -284,9 +284,13 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -284,9 +284,13 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
TypeOfExpression typeOfExpression; TypeOfExpression typeOfExpression;
typeOfExpression.setSnapshot(documents); typeOfExpression.setSnapshot(documents);
// We only want to show F1 if the tooltip matches the help id
bool m_showF1 = true;
foreach (Document::DiagnosticMessage m, doc->diagnosticMessages()) { foreach (Document::DiagnosticMessage m, doc->diagnosticMessages()) {
if (m.line() == lineNumber) { if (m.line() == lineNumber) {
m_toolTip = m.text(); m_toolTip = m.text();
m_showF1 = false;
break; break;
} }
} }
...@@ -295,12 +299,13 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -295,12 +299,13 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
foreach (const Document::Include &incl, doc->includes()) { foreach (const Document::Include &incl, doc->includes()) {
if (incl.line() == lineNumber) { if (incl.line() == lineNumber) {
m_toolTip = QDir::toNativeSeparators(incl.fileName()); m_toolTip = QDir::toNativeSeparators(incl.fileName());
m_helpId = QFileInfo(incl.fileName()).fileName();
break; break;
} }
} }
} }
if (m_toolTip.isEmpty()) { if (m_helpId.isEmpty()) {
// Move to the end of a qualified name // Move to the end of a qualified name
bool stop = false; bool stop = false;
while (!stop) { while (!stop) {
...@@ -314,7 +319,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -314,7 +319,7 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
} }
} }
// Fetch the expression's code. // Fetch the expression's code
ExpressionUnderCursor expressionUnderCursor; ExpressionUnderCursor expressionUnderCursor;
const QString expression = expressionUnderCursor(tc); const QString expression = expressionUnderCursor(tc);
...@@ -334,25 +339,27 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -334,25 +339,27 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
m_helpId = buildHelpId(resolvedSymbol, resolvedName); m_helpId = buildHelpId(resolvedSymbol, resolvedName);
Symbol *symbol = result.second; if (m_toolTip.isEmpty()) {
if (resolvedSymbol) Symbol *symbol = result.second;
symbol = resolvedSymbol; if (resolvedSymbol)
symbol = resolvedSymbol;
Overview overview; Overview overview;
overview.setShowArgumentNames(true); overview.setShowArgumentNames(true);
overview.setShowReturnTypes(true); overview.setShowReturnTypes(true);
overview.setShowFullyQualifiedNamed(true); overview.setShowFullyQualifiedNamed(true);
if (lookupSymbol && (lookupSymbol->isDeclaration() || lookupSymbol->isArgument())) { if (lookupSymbol && (lookupSymbol->isDeclaration() || lookupSymbol->isArgument())) {
m_toolTip = overview.prettyType(firstType, buildHelpId(lookupSymbol, lookupSymbol->name())); m_toolTip = overview.prettyType(firstType, buildHelpId(lookupSymbol, lookupSymbol->name()));
} else if (firstType->isClassType() || firstType->isEnumType() || } else if (firstType->isClassType() || firstType->isEnumType() ||
firstType->isForwardClassDeclarationType()) { firstType->isForwardClassDeclarationType()) {
m_toolTip = m_helpId; m_toolTip = m_helpId;
} else { } else {
m_toolTip = overview.prettyType(firstType, m_helpId); m_toolTip = overview.prettyType(firstType, m_helpId);
}
} }
} }
} }
...@@ -378,9 +385,11 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in ...@@ -378,9 +385,11 @@ void CppHoverHandler::updateHelpIdAndTooltip(TextEditor::ITextEditor *editor, in
m_toolTip = Qt::escape(m_toolTip); m_toolTip = Qt::escape(m_toolTip);
if (!m_helpId.isEmpty() && !m_helpEngine->linksForIdentifier(m_helpId).isEmpty()) { if (!m_helpId.isEmpty() && !m_helpEngine->linksForIdentifier(m_helpId).isEmpty()) {
m_toolTip = QString(QLatin1String("<table><tr><td valign=middle><nobr>%1</td>" if (m_showF1) {
"<td><img src=\":/cppeditor/images/f1.svg\"></td></tr></table>")) m_toolTip = QString(QLatin1String("<table><tr><td valign=middle><nobr>%1</td>"
.arg(m_toolTip); "<td><img src=\":/cppeditor/images/f1.svg\"></td></tr></table>"))
.arg(m_toolTip);
}
editor->setContextHelpId(m_helpId); editor->setContextHelpId(m_helpId);
} else if (!m_toolTip.isEmpty()) { } else if (!m_toolTip.isEmpty()) {
m_toolTip = QString(QLatin1String("<nobr>%1")).arg(m_toolTip); m_toolTip = QString(QLatin1String("<nobr>%1")).arg(m_toolTip);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment