diff --git a/assets/configures/editorstyle_cpp.support b/assets/configures/editorstyle_cpp.support index 024c1107f..d1da6bfa9 100644 --- a/assets/configures/editorstyle_cpp.support +++ b/assets/configures/editorstyle_cpp.support @@ -52,7 +52,7 @@ "Foreground": "#d6cf9a" }, "Comment": { - "Foreground": "#a8abb0" + "Foreground": "#969696" } }, "Light": { @@ -108,7 +108,7 @@ "Foreground": "#00677c" }, "Comment": { - "Foreground": "#008000" + "Foreground": "#8a8a8a" } } } diff --git a/src/common/lsp/client/client.cpp b/src/common/lsp/client/client.cpp index 922c3519a..cbeb93dfa 100644 --- a/src/common/lsp/client/client.cpp +++ b/src/common/lsp/client/client.cpp @@ -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) diff --git a/src/common/lsp/client/client.h b/src/common/lsp/client/client.h index e154dd559..e3606f1d5 100644 --- a/src/common/lsp/client/client.h +++ b/src/common/lsp/client/client.h @@ -144,7 +144,7 @@ public slots: void diagnostic(const newlsp::WorkspaceDiagnosticParams ¶ms); 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 diff --git a/src/common/lsp/protocol/new/extendedproject.cpp b/src/common/lsp/protocol/new/extendedproject.cpp index deff1dced..d678d9a18 100644 --- a/src/common/lsp/protocol/new/extendedproject.cpp +++ b/src/common/lsp/protocol/new/extendedproject.cpp @@ -15,13 +15,15 @@ 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) @@ -29,6 +31,7 @@ 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); } @@ -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; } @@ -59,14 +63,14 @@ ProjectKey::ProjectKey() qRegisterMetaType("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"); } ProjectKey::ProjectKey(const ProjectKey &other) - : language(other.language), workspace(other.workspace) + : language(other.language), workspace(other.workspace), outputDirectory(other.outputDirectory) { qRegisterMetaType("newlsp::ProjectKey"); } diff --git a/src/common/lsp/protocol/new/extendedproject.h b/src/common/lsp/protocol/new/extendedproject.h index 9120db178..c2ab7e249 100644 --- a/src/common/lsp/protocol/new/extendedproject.h +++ b/src/common/lsp/protocol/new/extendedproject.h @@ -8,36 +8,39 @@ #include #include -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); @@ -55,6 +58,6 @@ struct SelectLspServerParams }; std::string toJsonValueStr(const SelectLspServerParams &val); -} // namesapce newlsp +} // namesapce newlsp -#endif // EXTENDEDPROJECT_H +#endif // EXTENDEDPROJECT_H diff --git a/src/plugins/codeeditor/lsp/languageclienthandler.cpp b/src/plugins/codeeditor/lsp/languageclienthandler.cpp index d990cbd8c..adf0bed48 100644 --- a/src/plugins/codeeditor/lsp/languageclienthandler.cpp +++ b/src/plugins/codeeditor/lsp/languageclienthandler.cpp @@ -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(); @@ -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) diff --git a/src/plugins/codeeditor/lsp/languageworker.cpp b/src/plugins/codeeditor/lsp/languageworker.cpp index 0758628e5..fca28955b 100644 --- a/src/plugins/codeeditor/lsp/languageworker.cpp +++ b/src/plugins/codeeditor/lsp/languageworker.cpp @@ -37,13 +37,8 @@ void LanguageWorker::handleDocumentSemanticTokens(const QList &tokens cacheColumn += val.start.character; auto startPos = textEditor->positionFromLineIndex(cacheLine, cacheColumn); - auto wordEndPos = textEditor->SendScintilla(TextEditor::SCI_WORDENDPOSITION, static_cast(startPos), true); - auto wordStartPos = textEditor->SendScintilla(TextEditor::SCI_WORDSTARTPOSITION, static_cast(startPos), true); - if (startPos == 0 || wordEndPos == textEditor->length() || wordStartPos != startPos) - continue; - - QString sourceText = textEditor->text(static_cast(wordStartPos), static_cast(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 diff --git a/src/plugins/codeeditor/lsp/lspclientmanager.cpp b/src/plugins/codeeditor/lsp/lspclientmanager.cpp index ffb2077e7..7a0a52e6d 100644 --- a/src/plugins/codeeditor/lsp/lspclientmanager.cpp +++ b/src/plugins/codeeditor/lsp/lspclientmanager.cpp @@ -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); } diff --git a/src/plugins/codeeditor/lsp/private/languageclienthandler_p.h b/src/plugins/codeeditor/lsp/private/languageclienthandler_p.h index 6dd73dca3..a58dde85b 100644 --- a/src/plugins/codeeditor/lsp/private/languageclienthandler_p.h +++ b/src/plugins/codeeditor/lsp/private/languageclienthandler_p.h @@ -219,7 +219,7 @@ public slots: QList tokensCache; QList diagnosticCache; QString diagnosticFormat; - newlsp::ProjectKey prjectKey; + newlsp::ProjectKey projectKey; QTimer textChangedTimer; QTimer positionChangedTimer; diff --git a/src/plugins/cxx/lexer/scilexercpp.cpp b/src/plugins/cxx/lexer/scilexercpp.cpp index 75d660aa0..7ea064872 100644 --- a/src/plugins/cxx/lexer/scilexercpp.cpp +++ b/src/plugins/cxx/lexer/scilexercpp.cpp @@ -213,7 +213,9 @@ bool SciLexerCPP::isSupport(const QString &fileName) const QStringList SciLexerCPP::autoCompletionWordSeparators() const { QStringList wl; - wl << "::" << "->" << "."; + wl << "::" + << "->" + << "."; return wl; } @@ -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"); } diff --git a/src/tools/languageadapter/main.cpp b/src/tools/languageadapter/main.cpp index 6fcd2bc12..a868949d5 100644 --- a/src/tools/languageadapter/main.cpp +++ b/src/tools/languageadapter/main.cpp @@ -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)) { @@ -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"; @@ -146,7 +138,8 @@ void selectLspServer(const QJsonObject ¶ms) { 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);