forked from qt-creator/qt-creator
Code completion of doxygen tags.
This commit is contained in:
@@ -49,6 +49,9 @@ TokenUnderCursor::~TokenUnderCursor()
|
|||||||
SimpleToken TokenUnderCursor::operator()(const QTextCursor &cursor) const
|
SimpleToken TokenUnderCursor::operator()(const QTextCursor &cursor) const
|
||||||
{
|
{
|
||||||
SimpleLexer tokenize;
|
SimpleLexer tokenize;
|
||||||
|
tokenize.setObjCEnabled(true);
|
||||||
|
tokenize.setSkipComments(false);
|
||||||
|
|
||||||
QTextBlock block = cursor.block();
|
QTextBlock block = cursor.block();
|
||||||
int column = cursor.columnNumber();
|
int column = cursor.columnNumber();
|
||||||
|
|
||||||
|
@@ -15,8 +15,7 @@ HEADERS += cppplugin.h \
|
|||||||
cppeditorconstants.h \
|
cppeditorconstants.h \
|
||||||
cppeditorenums.h \
|
cppeditorenums.h \
|
||||||
cppeditor_global.h \
|
cppeditor_global.h \
|
||||||
cppclasswizard.h \
|
cppclasswizard.h
|
||||||
cppdoxygen.h
|
|
||||||
|
|
||||||
SOURCES += cppplugin.cpp \
|
SOURCES += cppplugin.cpp \
|
||||||
cppeditoractionhandler.cpp \
|
cppeditoractionhandler.cpp \
|
||||||
@@ -24,7 +23,6 @@ SOURCES += cppplugin.cpp \
|
|||||||
cpphighlighter.cpp \
|
cpphighlighter.cpp \
|
||||||
cpphoverhandler.cpp \
|
cpphoverhandler.cpp \
|
||||||
cppfilewizard.cpp \
|
cppfilewizard.cpp \
|
||||||
cppclasswizard.cpp \
|
cppclasswizard.cpp
|
||||||
cppdoxygen.cpp
|
|
||||||
|
|
||||||
RESOURCES += cppeditor.qrc
|
RESOURCES += cppeditor.qrc
|
||||||
|
@@ -32,7 +32,7 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include "cpphighlighter.h"
|
#include "cpphighlighter.h"
|
||||||
#include "cppdoxygen.h"
|
#include <cpptools/cppdoxygen.h>
|
||||||
|
|
||||||
#include <Token.h>
|
#include <Token.h>
|
||||||
#include <cplusplus/SimpleLexer.h>
|
#include <cplusplus/SimpleLexer.h>
|
||||||
@@ -341,8 +341,8 @@ void CppHighlighter::highlightDoxygenComment(const QString &text, int position,
|
|||||||
while (it->isLetterOrNumber() || it->unicode() == '_')
|
while (it->isLetterOrNumber() || it->unicode() == '_')
|
||||||
++it;
|
++it;
|
||||||
|
|
||||||
int k = classifyDoxygen(start, it - start);
|
int k = CppTools::classifyDoxygenTag(start, it - start);
|
||||||
if (k != T_DOXY_IDENTIFIER) {
|
if (k != CppTools::T_DOXY_IDENTIFIER) {
|
||||||
setFormat(initial, start - uc - initial, format);
|
setFormat(initial, start - uc - initial, format);
|
||||||
setFormat(start - uc - 1, it - start + 1, kwFormat);
|
setFormat(start - uc - 1, it - start + 1, kwFormat);
|
||||||
initial = it - uc;
|
initial = it - uc;
|
||||||
|
@@ -32,8 +32,8 @@
|
|||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
#include "cppcodecompletion.h"
|
#include "cppcodecompletion.h"
|
||||||
|
|
||||||
#include "cppmodelmanager.h"
|
#include "cppmodelmanager.h"
|
||||||
|
#include "cppdoxygen.h"
|
||||||
|
|
||||||
#include <Control.h>
|
#include <Control.h>
|
||||||
#include <AST.h>
|
#include <AST.h>
|
||||||
@@ -371,46 +371,54 @@ static int startOfOperator(TextEditor::ITextEditable *editor,
|
|||||||
const QChar ch3 = pos > 1 ? editor->characterAt(pos - 3) : QChar();
|
const QChar ch3 = pos > 1 ? editor->characterAt(pos - 3) : QChar();
|
||||||
|
|
||||||
int start = pos;
|
int start = pos;
|
||||||
|
int k = T_EOF_SYMBOL;
|
||||||
|
|
||||||
if (ch2 != QLatin1Char('.') && ch == QLatin1Char('.')) {
|
if (ch2 != QLatin1Char('.') && ch == QLatin1Char('.')) {
|
||||||
if (kind)
|
k = T_DOT;
|
||||||
*kind = T_DOT;
|
|
||||||
--start;
|
--start;
|
||||||
} else if (wantFunctionCall && ch == QLatin1Char('(')) {
|
} else if (wantFunctionCall && ch == QLatin1Char('(')) {
|
||||||
if (kind)
|
k = T_LPAREN;
|
||||||
*kind = T_LPAREN;
|
|
||||||
--start;
|
--start;
|
||||||
} else if (ch2 == QLatin1Char(':') && ch == QLatin1Char(':')) {
|
} else if (ch2 == QLatin1Char(':') && ch == QLatin1Char(':')) {
|
||||||
if (kind)
|
k = T_COLON_COLON;
|
||||||
*kind = T_COLON_COLON;
|
|
||||||
start -= 2;
|
start -= 2;
|
||||||
} else if (ch2 == QLatin1Char('-') && ch == QLatin1Char('>')) {
|
} else if (ch2 == QLatin1Char('-') && ch == QLatin1Char('>')) {
|
||||||
if (kind)
|
k = T_ARROW;
|
||||||
*kind = T_ARROW;
|
|
||||||
start -= 2;
|
start -= 2;
|
||||||
} else if (ch2 == QLatin1Char('.') && ch == QLatin1Char('*')) {
|
} else if (ch2 == QLatin1Char('.') && ch == QLatin1Char('*')) {
|
||||||
if (kind)
|
k = T_DOT_STAR;
|
||||||
*kind = T_DOT_STAR;
|
|
||||||
start -= 2;
|
start -= 2;
|
||||||
} else if (ch3 == QLatin1Char('-') && ch2 == QLatin1Char('>') && ch == QLatin1Char('*')) {
|
} else if (ch3 == QLatin1Char('-') && ch2 == QLatin1Char('>') && ch == QLatin1Char('*')) {
|
||||||
if (kind)
|
k = T_ARROW_STAR;
|
||||||
*kind = T_ARROW_STAR;
|
|
||||||
start -= 3;
|
start -= 3;
|
||||||
|
} else if (ch == QLatin1Char('@') || ch == QLatin1Char('\\')) {
|
||||||
|
k = T_DOXY_COMMENT;
|
||||||
|
--start;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (start != pos) {
|
if (start == pos)
|
||||||
TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
|
return start;
|
||||||
QTextCursor tc(edit->textCursor());
|
|
||||||
tc.setPosition(pos);
|
TextEditor::BaseTextEditor *edit = qobject_cast<TextEditor::BaseTextEditor *>(editor->widget());
|
||||||
static CPlusPlus::TokenUnderCursor tokenUnderCursor;
|
QTextCursor tc(edit->textCursor());
|
||||||
const SimpleToken tk = tokenUnderCursor(tc);
|
tc.setPosition(pos);
|
||||||
if (tk.isComment() || tk.isLiteral()) {
|
|
||||||
if (kind)
|
static CPlusPlus::TokenUnderCursor tokenUnderCursor;
|
||||||
*kind = T_EOF_SYMBOL;
|
const SimpleToken tk = tokenUnderCursor(tc);
|
||||||
return pos;
|
|
||||||
}
|
if (k == T_DOXY_COMMENT && tk.isNot(T_DOXY_COMMENT)) {
|
||||||
|
k = T_EOF_SYMBOL;
|
||||||
|
start = pos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
else if (tk.is(T_COMMENT) || tk.isLiteral()) {
|
||||||
|
k = T_EOF_SYMBOL;
|
||||||
|
start = pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (kind)
|
||||||
|
*kind = k;
|
||||||
|
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -457,15 +465,31 @@ int CppCodeCompletion::startCompletion(TextEditor::ITextEditable *editor)
|
|||||||
ExpressionUnderCursor expressionUnderCursor;
|
ExpressionUnderCursor expressionUnderCursor;
|
||||||
QString expression;
|
QString expression;
|
||||||
|
|
||||||
|
|
||||||
|
if (m_completionOperator == T_DOXY_COMMENT) {
|
||||||
|
for (int i = 1; i < T_DOXY_LAST_TAG; ++i) {
|
||||||
|
TextEditor::CompletionItem item(this);
|
||||||
|
item.m_text.append(QString::fromLatin1(doxygenTagSpell(i)));
|
||||||
|
m_completions.append(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
return m_startPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (m_completionOperator) {
|
if (m_completionOperator) {
|
||||||
QTextCursor tc(edit->document());
|
QTextCursor tc(edit->document());
|
||||||
tc.setPosition(endOfExpression);
|
tc.setPosition(endOfExpression);
|
||||||
|
|
||||||
expression = expressionUnderCursor(tc);
|
expression = expressionUnderCursor(tc);
|
||||||
|
|
||||||
if (m_completionOperator == T_LPAREN) {
|
if (m_completionOperator == T_LPAREN) {
|
||||||
if (expression.endsWith(QLatin1String("SIGNAL")))
|
if (expression.endsWith(QLatin1String("SIGNAL")))
|
||||||
m_completionOperator = T_SIGNAL;
|
m_completionOperator = T_SIGNAL;
|
||||||
|
|
||||||
else if (expression.endsWith(QLatin1String("SLOT")))
|
else if (expression.endsWith(QLatin1String("SLOT")))
|
||||||
m_completionOperator = T_SLOT;
|
m_completionOperator = T_SLOT;
|
||||||
|
|
||||||
else if (editor->position() != endOfOperator) {
|
else if (editor->position() != endOfOperator) {
|
||||||
// We don't want a function completion when the cursor isn't at the opening brace
|
// We don't want a function completion when the cursor isn't at the opening brace
|
||||||
expression.clear();
|
expression.clear();
|
||||||
|
@@ -34,20 +34,138 @@
|
|||||||
#include <QString>
|
#include <QString>
|
||||||
#include "cppdoxygen.h"
|
#include "cppdoxygen.h"
|
||||||
|
|
||||||
using namespace CppEditor::Internal;
|
using namespace CppTools;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
TODO:
|
||||||
~
|
~
|
||||||
@
|
@
|
||||||
$
|
$
|
||||||
\
|
\
|
||||||
#
|
#
|
||||||
f[
|
f[
|
||||||
f]
|
f]
|
||||||
f$
|
f$
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
static const char *doxy_token_spell[] = {
|
||||||
|
"identifier",
|
||||||
|
|
||||||
|
"arg",
|
||||||
|
"attention",
|
||||||
|
"author",
|
||||||
|
"callgraph",
|
||||||
|
"code",
|
||||||
|
"dot",
|
||||||
|
"else",
|
||||||
|
"endcode",
|
||||||
|
"endcond",
|
||||||
|
"enddot",
|
||||||
|
"endhtmlonly",
|
||||||
|
"endif",
|
||||||
|
"endlatexonly",
|
||||||
|
"endlink",
|
||||||
|
"endmanonly",
|
||||||
|
"endverbatim",
|
||||||
|
"endxmlonly",
|
||||||
|
"hideinitializer",
|
||||||
|
"htmlonly",
|
||||||
|
"interface",
|
||||||
|
"internal",
|
||||||
|
"invariant",
|
||||||
|
"latexonly",
|
||||||
|
"li",
|
||||||
|
"manonly",
|
||||||
|
"n",
|
||||||
|
"nosubgrouping",
|
||||||
|
"note",
|
||||||
|
"only",
|
||||||
|
"post",
|
||||||
|
"pre",
|
||||||
|
"remarks",
|
||||||
|
"return",
|
||||||
|
"returns",
|
||||||
|
"sa",
|
||||||
|
"see",
|
||||||
|
"showinitializer",
|
||||||
|
"since",
|
||||||
|
"test",
|
||||||
|
"todo",
|
||||||
|
"verbatim",
|
||||||
|
"warning",
|
||||||
|
"xmlonly",
|
||||||
|
|
||||||
|
"a",
|
||||||
|
"addtogroup",
|
||||||
|
"anchor",
|
||||||
|
"b",
|
||||||
|
"c",
|
||||||
|
"class",
|
||||||
|
"cond",
|
||||||
|
"copydoc",
|
||||||
|
"def",
|
||||||
|
"dontinclude",
|
||||||
|
"dotfile",
|
||||||
|
"e",
|
||||||
|
"elseif",
|
||||||
|
"em",
|
||||||
|
"enum",
|
||||||
|
"example",
|
||||||
|
"exception",
|
||||||
|
"exceptions",
|
||||||
|
"file",
|
||||||
|
"htmlinclude",
|
||||||
|
"if",
|
||||||
|
"ifnot",
|
||||||
|
"include",
|
||||||
|
"link",
|
||||||
|
"namespace",
|
||||||
|
"p",
|
||||||
|
"package",
|
||||||
|
"ref",
|
||||||
|
"relates",
|
||||||
|
"relatesalso",
|
||||||
|
"retval",
|
||||||
|
"throw",
|
||||||
|
"throws",
|
||||||
|
"verbinclude",
|
||||||
|
"version",
|
||||||
|
"xrefitem",
|
||||||
|
|
||||||
|
"param",
|
||||||
|
|
||||||
|
"image",
|
||||||
|
|
||||||
|
"defgroup",
|
||||||
|
"page",
|
||||||
|
"paragraph",
|
||||||
|
"section",
|
||||||
|
"struct",
|
||||||
|
"subsection",
|
||||||
|
"subsubsection",
|
||||||
|
"union",
|
||||||
|
"weakgroup",
|
||||||
|
|
||||||
|
"addindex",
|
||||||
|
"brief",
|
||||||
|
"bug",
|
||||||
|
"date",
|
||||||
|
"deprecated",
|
||||||
|
"fn",
|
||||||
|
"ingroup",
|
||||||
|
"line",
|
||||||
|
"mainpage",
|
||||||
|
"name",
|
||||||
|
"overload",
|
||||||
|
"par",
|
||||||
|
"short",
|
||||||
|
"skip",
|
||||||
|
"skipline",
|
||||||
|
"typedef",
|
||||||
|
"until",
|
||||||
|
"var"
|
||||||
|
};
|
||||||
|
|
||||||
static inline int classify1(const QChar *s) {
|
static inline int classify1(const QChar *s) {
|
||||||
if (s[0].unicode() == 'a') {
|
if (s[0].unicode() == 'a') {
|
||||||
return T_DOXY_A;
|
return T_DOXY_A;
|
||||||
@@ -1490,7 +1608,10 @@ static inline int classify15(const QChar *s) {
|
|||||||
return T_DOXY_IDENTIFIER;
|
return T_DOXY_IDENTIFIER;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CppEditor::Internal::classifyDoxygen(const QChar *s, int n) {
|
const char *CppTools::doxygenTagSpell(int index)
|
||||||
|
{ return doxy_token_spell[index]; }
|
||||||
|
|
||||||
|
int CppTools::classifyDoxygenTag(const QChar *s, int n) {
|
||||||
switch (n) {
|
switch (n) {
|
||||||
case 1: return classify1(s);
|
case 1: return classify1(s);
|
||||||
case 2: return classify2(s);
|
case 2: return classify2(s);
|
@@ -30,8 +30,10 @@
|
|||||||
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
|
** version 1.3, included in the file GPL_EXCEPTION.txt in this package.
|
||||||
**
|
**
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
namespace CppEditor {
|
|
||||||
namespace Internal {
|
#include "cpptools_global.h"
|
||||||
|
|
||||||
|
namespace CppTools {
|
||||||
|
|
||||||
enum DoxygenReservedWord {
|
enum DoxygenReservedWord {
|
||||||
T_DOXY_IDENTIFIER = 0,
|
T_DOXY_IDENTIFIER = 0,
|
||||||
@@ -150,11 +152,12 @@ enum DoxygenReservedWord {
|
|||||||
T_DOXY_UNTIL,
|
T_DOXY_UNTIL,
|
||||||
T_DOXY_VAR,
|
T_DOXY_VAR,
|
||||||
|
|
||||||
|
T_DOXY_LAST_TAG
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
int classifyDoxygen(const QChar *s, int n);
|
CPPTOOLS_EXPORT int classifyDoxygenTag(const QChar *s, int n);
|
||||||
|
CPPTOOLS_EXPORT const char *doxygenTagSpell(int index);
|
||||||
|
|
||||||
|
|
||||||
} // namespace Internal
|
|
||||||
} // namespace CppEditor::Internal
|
} // namespace CppEditor::Internal
|
||||||
|
|
@@ -19,7 +19,8 @@ HEADERS += completionsettingspage.h \
|
|||||||
cpptoolsconstants.h \
|
cpptoolsconstants.h \
|
||||||
cpptoolseditorsupport.h \
|
cpptoolseditorsupport.h \
|
||||||
cpptoolsplugin.h \
|
cpptoolsplugin.h \
|
||||||
searchsymbols.h
|
searchsymbols.h \
|
||||||
|
cppdoxygen.h
|
||||||
|
|
||||||
SOURCES += completionsettingspage.cpp \
|
SOURCES += completionsettingspage.cpp \
|
||||||
cppclassesfilter.cpp \
|
cppclassesfilter.cpp \
|
||||||
@@ -29,6 +30,7 @@ SOURCES += completionsettingspage.cpp \
|
|||||||
cppquickopenfilter.cpp \
|
cppquickopenfilter.cpp \
|
||||||
cpptoolseditorsupport.cpp \
|
cpptoolseditorsupport.cpp \
|
||||||
cpptoolsplugin.cpp \
|
cpptoolsplugin.cpp \
|
||||||
searchsymbols.cpp
|
searchsymbols.cpp \
|
||||||
|
cppdoxygen.cpp
|
||||||
|
|
||||||
FORMS += completionsettingspage.ui
|
FORMS += completionsettingspage.ui
|
||||||
|
@@ -34,10 +34,12 @@
|
|||||||
#ifndef CPPTOOLS_GLOBAL_H
|
#ifndef CPPTOOLS_GLOBAL_H
|
||||||
#define CPPTOOLS_GLOBAL_H
|
#define CPPTOOLS_GLOBAL_H
|
||||||
|
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
#if defined(CPPTOOLS_LIBRARY)
|
#if defined(CPPTOOLS_LIBRARY)
|
||||||
# define CPPTOOLS_EXPORT Q_DECL_EXPORT
|
# define CPPTOOLS_EXPORT Q_DECL_EXPORT
|
||||||
#else
|
#else
|
||||||
# define CPPTOOLS_EXPORT Q_DECL_IMPORT
|
# define CPPTOOLS_EXPORT Q_DECL_IMPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif // CPPTOOLS_GLOBAL_H
|
#endif // CPPTOOLS_GLOBAL_H
|
||||||
|
Reference in New Issue
Block a user