Skip to content

Commit

Permalink
fix: Fixed code coloring issues
Browse files Browse the repository at this point in the history
Fixed a coloring issue where 'QT_DEBUG' macro could not be recognized

Log: fix issue
  • Loading branch information
Kakueeen authored and deepin-mozart committed Aug 8, 2024
1 parent 6760172 commit bec24c5
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 90 deletions.
4 changes: 2 additions & 2 deletions assets/configures/editorstyle_cpp.support
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
"Foreground": "#d6cf9a"
},
"Comment": {
"Foreground": "#a8abb0"
"Foreground": "#969696"
}
},
"Light": {
Expand Down Expand Up @@ -108,7 +108,7 @@
"Foreground": "#00677c"
},
"Comment": {
"Foreground": "#008000"
"Foreground": "#8a8a8a"
}
}
}
5 changes: 3 additions & 2 deletions src/common/lsp/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,12 @@ void Client::selectLspServer(const newlsp::ProjectKey &key)
d->writeLspData(newlsp::notificationData(__FUNCTION__, params).toUtf8());
}

void Client::initRequest(const QString &compile)
void Client::initRequest()
{
QString langQStr = QString::fromStdString(d->proKey.language);
QString workQStr = QString::fromStdString(d->proKey.workspace);
d->callMethod(lsp::V_INITIALIZE, lsp::initialize(workQStr, langQStr, compile));
QString outputStr = QString::fromStdString(d->proKey.outputDirectory);
d->callMethod(lsp::V_INITIALIZE, lsp::initialize(workQStr, langQStr, outputStr));
}

void Client::openRequest(const QString &filePath)
Expand Down
2 changes: 1 addition & 1 deletion src/common/lsp/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public slots:
void diagnostic(const newlsp::WorkspaceDiagnosticParams &params);

void selectLspServer(const newlsp::ProjectKey &key);
void initRequest(const QString &compile); // yes
void initRequest(); // yes
void shutdownRequest();
void exitRequest();
void openRequest(const QString &filePath); // yes
Expand Down
14 changes: 9 additions & 5 deletions src/common/lsp/protocol/new/extendedproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,23 @@ namespace newlsp
uint qHash(const ProjectKey &key, uint seed)
{
return ::qHash(QString::fromStdString(key.workspace)
+ QString::fromStdString(key.language), seed);
+ QString::fromStdString(key.language)
+ QString::fromStdString(key.outputDirectory), seed);
}

bool operator ==(const ProjectKey &t1, const ProjectKey &t2)
{
return t1.workspace == t2.workspace
&& t2.language == t2.language;
&& t1.language == t2.language
&& t1.outputDirectory == t2.outputDirectory;
}

std::string toJsonValueStr(const ProjectKey &val)
{
std::string ret;
ret = json::addValue(ret, json::KV{"language", val.language});
ret = json::addValue(ret, json::KV{"workspace", val.workspace});
ret = json::addValue(ret, json::KV{"output", val.outputDirectory});
return json::addScope(ret);
}

Expand All @@ -51,6 +54,7 @@ QJsonObject toQJsonObject(const ProjectKey &val)
QJsonObject ret;
ret["language"] = QString::fromStdString(val.language);
ret["workspace"] = QString::fromStdString(val.workspace);
ret["output"] = QString::fromStdString(val.outputDirectory);
return ret;
}

Expand All @@ -59,14 +63,14 @@ ProjectKey::ProjectKey()
qRegisterMetaType<newlsp::ProjectKey>("newlsp::ProjectKey");
}

ProjectKey::ProjectKey(const std::string &language, const std::string &workspace)
: language(language), workspace(workspace)
ProjectKey::ProjectKey(const std::string &language, const std::string &workspace, const std::string &output)
: language(language), workspace(workspace), outputDirectory(output)
{
qRegisterMetaType<newlsp::ProjectKey>("newlsp::ProjectKey");
}

ProjectKey::ProjectKey(const ProjectKey &other)
: language(other.language), workspace(other.workspace)
: language(other.language), workspace(other.workspace), outputDirectory(other.outputDirectory)
{
qRegisterMetaType<newlsp::ProjectKey>("newlsp::ProjectKey");
}
Expand Down
37 changes: 20 additions & 17 deletions src/common/lsp/protocol/new/extendedproject.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,39 @@
#include <QJsonObject>
#include <string>

namespace newlsp
{
namespace newlsp {

inline const std::string Cxx{"C/C++"};
inline const std::string Java{"Java"};
inline const std::string Python{"Python"};
inline const std::string JS{"JS"};
inline const std::string Cxx { "C/C++" };
inline const std::string Java { "Java" };
inline const std::string Python { "Python" };
inline const std::string JS { "JS" };

inline const std::string language{"language"};
inline const std::string workspace{"workspace"};
inline const std::string language { "language" };
inline const std::string workspace { "workspace" };
inline const std::string output { "output" };

inline const std::string lauchLspServer{"lanuchLspServer"};
inline const std::string selectLspServer{"selectLspServer"};
inline const std::string lauchLspServer { "lanuchLspServer" };
inline const std::string selectLspServer { "selectLspServer" };

struct ProjectKey
{
std::string language;
std::string workspace;
std::string outputDirectory;
ProjectKey();
ProjectKey(const std::string &language, const std::string &workspace);
ProjectKey(const std::string &language, const std::string &workspace, const std::string &output);
ProjectKey(const ProjectKey &other);
bool isValid() const { return !workspace.empty() && !language.empty();}
bool operator == (const ProjectKey &other) {
bool isValid() const { return !workspace.empty() && !language.empty() && !outputDirectory.empty(); }
bool operator==(const ProjectKey &other)
{
return language == other.language
&& workspace == other.workspace;
&& workspace == other.workspace
&& outputDirectory == other.outputDirectory;
}
};

uint qHash(const ProjectKey &key, uint seed = 0);
bool operator == (const ProjectKey &t1, const ProjectKey &t2);
bool operator==(const ProjectKey &t1, const ProjectKey &t2);
std::string toJsonValueStr(const ProjectKey &val);
QJsonObject toQJsonObject(const ProjectKey &val);

Expand All @@ -55,6 +58,6 @@ struct SelectLspServerParams
};
std::string toJsonValueStr(const SelectLspServerParams &val);

} // namesapce newlsp
} // namesapce newlsp

#endif // EXTENDEDPROJECT_H
#endif // EXTENDEDPROJECT_H
24 changes: 10 additions & 14 deletions src/plugins/codeeditor/lsp/languageclienthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ int LanguageClientHandlerPrivate::wordPostion()

newlsp::Client *LanguageClientHandlerPrivate::getClient()
{
if (prjectKey.isValid())
return LSPClientManager::instance()->get(prjectKey);
if (projectKey.isValid())
return LSPClientManager::instance()->get(projectKey);

auto prjSrv = dpfGetService(dpfservice::ProjectService);
const auto &filePath = editor->getFile();
Expand All @@ -198,25 +198,21 @@ newlsp::Client *LanguageClientHandlerPrivate::getClient()
if (!files.contains(filePath))
continue;

prjectKey.language = prj.language().toStdString();
prjectKey.workspace = prj.workspaceFolder().toStdString();
projectKey.workspace = prj.workspaceFolder().toStdString();
projectKey.outputDirectory = prj.buildFolder().toStdString();
break;
}

if (!prjectKey.isValid()) {
if (projectKey.workspace.empty()) {
auto prj = prjSrv->getActiveProjectInfo();
prjectKey.language = prj.language().toStdString();
prjectKey.workspace = prj.workspaceFolder().toStdString();
projectKey.workspace = prj.workspaceFolder().toStdString();
projectKey.outputDirectory = prj.buildFolder().toStdString();
}

auto fileLangId = support_file::Language::id(filePath);
if (fileLangId != prjectKey.language.c_str()) {
fileLangId = support_file::Language::idAlias(fileLangId);
if (fileLangId != prjectKey.language.c_str())
return nullptr;
}
auto id = support_file::Language::id(filePath);
projectKey.language = support_file::Language::idAlias(id).toStdString();

return LSPClientManager::instance()->get(prjectKey);
return LSPClientManager::instance()->get(projectKey);
}

void LanguageClientHandlerPrivate::handleDiagnostics(const newlsp::PublishDiagnosticsParams &data)
Expand Down
9 changes: 2 additions & 7 deletions src/plugins/codeeditor/lsp/languageworker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,8 @@ void LanguageWorker::handleDocumentSemanticTokens(const QList<lsp::Data> &tokens

cacheColumn += val.start.character;
auto startPos = textEditor->positionFromLineIndex(cacheLine, cacheColumn);
auto wordEndPos = textEditor->SendScintilla(TextEditor::SCI_WORDENDPOSITION, static_cast<ulong>(startPos), true);
auto wordStartPos = textEditor->SendScintilla(TextEditor::SCI_WORDSTARTPOSITION, static_cast<ulong>(startPos), true);
if (startPos == 0 || wordEndPos == textEditor->length() || wordStartPos != startPos)
continue;

QString sourceText = textEditor->text(static_cast<int>(wordStartPos), static_cast<int>(wordEndPos));
if (!sourceText.isEmpty() && sourceText.length() == val.length) {
QString sourceText = textEditor->text(startPos, startPos + val.length);
if (!sourceText.isEmpty()) {
QString tokenValue = clientHandler->tokenToDefine(val.tokenType);
QColor color = clientHandler->symbolIndicColor(tokenValue, {});
#if 0
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/codeeditor/lsp/lspclientmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ newlsp::Client *LSPClientManager::get(const newlsp::ProjectKey &key)
auto client = new newlsp::Client();
qApp->metaObject()->invokeMethod(client, "selectLspServer", Q_ARG(const newlsp::ProjectKey &, key));
QString complieDB_Path = QString::fromStdString(key.workspace) + QDir::separator() + ".unioncode";
qApp->metaObject()->invokeMethod(client, "initRequest", Q_ARG(const QString &, complieDB_Path));
qApp->metaObject()->invokeMethod(client, "initRequest");
clientHash.insert(key, client);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public slots:
QList<lsp::Data> tokensCache;
QList<DiagnosticCache> diagnosticCache;
QString diagnosticFormat;
newlsp::ProjectKey prjectKey;
newlsp::ProjectKey projectKey;

QTimer textChangedTimer;
QTimer positionChangedTimer;
Expand Down
56 changes: 26 additions & 30 deletions src/plugins/cxx/lexer/scilexercpp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,9 @@ bool SciLexerCPP::isSupport(const QString &fileName) const
QStringList SciLexerCPP::autoCompletionWordSeparators() const
{
QStringList wl;
wl << "::" << "->" << ".";
wl << "::"
<< "->"
<< ".";

return wl;
}
Expand Down Expand Up @@ -258,77 +260,71 @@ QColor SciLexerCPP::defaultColor(int style) const
bool isDarkTheme = DGuiApplicationHelper::instance()->themeType() == DGuiApplicationHelper::DarkType;
switch (style) {
case Default:
case InactiveDefault:
return isDarkTheme ? QColor("#d6cf9a") : QColor("#000000");

case Comment:
case CommentLine:
case InactiveComment:
case InactiveCommentLine:
case CommentDoc:
case InactiveCommentDoc:
case CommentLineDoc:
case InactiveCommentLineDoc:
case PreProcessorCommentLineDoc:
case InactivePreProcessorCommentLineDoc:
case CommentDocKeyword:
case CommentDocKeywordError:
case InactiveCommentDocKeyword:
case InactiveCommentDocKeywordError:
case PreProcessorComment:
case InactivePreProcessorComment:
return isDarkTheme ? QColor("#a8abb0") : QColor("#008000");

case Number:
case InactiveNumber:
return isDarkTheme ? QColor("#8a602c") : QColor("#000080");

case Keyword:
case InactiveKeyword:
return isDarkTheme ? QColor("#45c6d6") : QColor("#808000");

case DoubleQuotedString:
case SingleQuotedString:
case RawString:
case InactiveDoubleQuotedString:
case InactiveSingleQuotedString:
case InactiveRawString:
return isDarkTheme ? QColor("#d69545") : QColor("#008000");

case PreProcessor:
case InactivePreProcessor:
return isDarkTheme ? QColor("#ff6aad") : QColor("#000080");

case Operator:
case UnclosedString:
case InactiveUnclosedString:
case InactiveOperator:
return isDarkTheme ? QColor("#d6cf9a") : QColor("#000000");

case VerbatimString:
case TripleQuotedVerbatimString:
case InactiveVerbatimString:
case InactiveTripleQuotedVerbatimString:
case HashQuotedString:
case InactiveHashQuotedString:
return isDarkTheme ? QColor("#d69545") : QColor("#008000");

case Regex:
return isDarkTheme ? QColor("#45c6d6") : QColor("#3f7f3f");

case InactiveDefault:
case InactiveUUID:
case InactiveCommentLineDoc:
case InactiveKeywordSet2:
case InactiveCommentDocKeyword:
case InactiveCommentDocKeywordError:
case InactivePreProcessorCommentLineDoc:
case InactiveComment:
case InactiveCommentLine:
case InactiveNumber:
case InactiveVerbatimString:
case InactiveTripleQuotedVerbatimString:
case InactiveHashQuotedString:
case InactiveCommentDoc:
case InactiveKeyword:
case InactiveDoubleQuotedString:
case InactiveSingleQuotedString:
case InactiveRawString:
case InactivePreProcessor:
case InactiveOperator:
case InactiveIdentifier:
case InactiveGlobalClass:
case InactiveUnclosedString:
case InactiveRegex:
case InactivePreProcessorComment:
case InactiveTaskMarker:
case InactiveUserLiteral:
return isDarkTheme ? QColor("#969696") : QColor("#8a8a8a");
return isDarkTheme ? QColor("#45c6d6") : QColor("#3f7f3f");

case UserLiteral:
case InactiveUserLiteral:
return isDarkTheme ? QColor("#d6cf9a") : QColor("#c06000");

case TaskMarker:
case InactiveTaskMarker:
return isDarkTheme ? QColor("#ff6aad") : QColor("#be07ff");
}

Expand Down
13 changes: 3 additions & 10 deletions src/tools/languageadapter/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@ QProcess *createCxxServ(const newlsp::ProjectKey &key)
if (key.language != newlsp::Cxx)
return nullptr;

QString projectCacheDir = ".unioncode";
QString compileDB_Path = QString::fromStdString(key.workspace) + QDir::separator() + projectCacheDir;
QStringList compileDB_CMD_As;
compileDB_CMD_As << "-S" << QString::fromStdString(key.workspace);
compileDB_CMD_As << "-B" << compileDB_Path;
compileDB_CMD_As << "-DCMAKE_EXPORT_COMPILE_COMMANDS=1";
QProcess::execute("/usr/bin/cmake", compileDB_CMD_As);

QStringList procAs;
QString clangd = "clangd-13";
if (ProcessUtil::exists(clangd)) {
Expand All @@ -37,7 +29,7 @@ QProcess *createCxxServ(const newlsp::ProjectKey &key)
}

procAs << "--log=verbose";
procAs << QString("--compile-commands-dir=%0").arg(compileDB_Path);
procAs << QString("--compile-commands-dir=%0").arg(key.outputDirectory.c_str());
procAs << "--clang-tidy";
procAs << "--completion-style=bundled";
procAs << "--limit-results=500";
Expand Down Expand Up @@ -146,7 +138,8 @@ void selectLspServer(const QJsonObject &params)
{
QString language = params.value(QString::fromStdString(newlsp::language)).toString();
QString workspace = params.value(QString::fromStdString(newlsp::workspace)).toString();
newlsp::ProjectKey projectKey {language.toStdString(), workspace.toStdString()};
QString output = params.value(QString::fromStdString(newlsp::output)).toString();
newlsp::ProjectKey projectKey {language.toStdString(), workspace.toStdString(), output.toStdString()};
JsonRpcCallProxy::ins().setSelect(projectKey);
QProcess *proc = JsonRpcCallProxy::ins().value(projectKey);

Expand Down

0 comments on commit bec24c5

Please sign in to comment.