summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-language-server.cpp
diff options
context:
space:
mode:
authorEllie Hermaszewska <ellieh@nvidia.com>2024-10-29 14:49:26 +0800
committerGitHub <noreply@github.com>2024-10-29 14:49:26 +0800
commitf65d756bff8d4c5cbc15bd0322a2ae8e6b896a21 (patch)
treeea1d61342cd29368e19135000ec2948813096205 /source/slang/slang-language-server.cpp
parenta729c15e9dce9f5116a38afc66329ab2ca4cea54 (diff)
format
* format * Minor test fixes * enable checking cpp format in ci
Diffstat (limited to 'source/slang/slang-language-server.cpp')
-rw-r--r--source/slang/slang-language-server.cpp528
1 files changed, 352 insertions, 176 deletions
diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp
index 80d9c2ef8..f9cc6f711 100644
--- a/source/slang/slang-language-server.cpp
+++ b/source/slang/slang-language-server.cpp
@@ -4,34 +4,44 @@
// https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-
-#include "../core/slang-secure-crt.h"
-#include "../core/slang-char-util.h"
-#include "../core/slang-string-util.h"
+#include "slang-language-server.h"
-#include "slang-com-helper.h"
+#include "../../tools/platform/performance-counter.h"
#include "../compiler-core/slang-json-native.h"
#include "../compiler-core/slang-json-rpc-connection.h"
#include "../compiler-core/slang-language-server-protocol.h"
+#include "../core/slang-char-util.h"
+#include "../core/slang-secure-crt.h"
+#include "../core/slang-string-util.h"
+#include "slang-ast-print.h"
#include "slang-check-impl.h"
-#include "slang-language-server.h"
-#include "slang-workspace-version.h"
+#include "slang-com-helper.h"
+#include "slang-doc-markdown-writer.h"
#include "slang-language-server-ast-lookup.h"
#include "slang-language-server-completion.h"
-#include "slang-language-server-semantic-tokens.h"
#include "slang-language-server-document-symbols.h"
#include "slang-language-server-inlay-hints.h"
-#include "slang-ast-print.h"
-#include "slang-doc-markdown-writer.h"
+#include "slang-language-server-semantic-tokens.h"
#include "slang-mangle.h"
-#include "../../tools/platform/performance-counter.h"
+#include "slang-workspace-version.h"
-#define SLANG_LS_RETURN_ON_SUCCESS(x) { auto _res = (x); if (_res.returnCode == SLANG_OK) return _res; }
-#define SLANG_LS_RETURN_ON_FAIL(x) { auto _res = (x); if (SLANG_FAILED(_res.returnCode)) return _res; }
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#define SLANG_LS_RETURN_ON_SUCCESS(x) \
+ { \
+ auto _res = (x); \
+ if (_res.returnCode == SLANG_OK) \
+ return _res; \
+ }
+#define SLANG_LS_RETURN_ON_FAIL(x) \
+ { \
+ auto _res = (x); \
+ if (SLANG_FAILED(_res.returnCode)) \
+ return _res; \
+ }
namespace Slang
{
@@ -61,7 +71,7 @@ SlangResult LanguageServerCore::init(const InitializeParams& args)
SlangResult LanguageServer::init(const InitializeParams& args)
{
SLANG_RETURN_ON_FAIL(m_connection->initWithStdStreams(JSONRPCConnection::CallStyle::Object));
-
+
m_typeMap = JSONNativeUtil::getTypeFuncsMap();
return m_core.init(args);
@@ -81,7 +91,10 @@ slang::IGlobalSession* LanguageServerCore::getOrCreateGlobalSession()
return m_session;
}
-void LanguageServer::resetDiagnosticUpdateTime() { m_lastDiagnosticUpdateTime = std::chrono::system_clock::now(); }
+void LanguageServer::resetDiagnosticUpdateTime()
+{
+ m_lastDiagnosticUpdateTime = std::chrono::system_clock::now();
+}
String uriToCanonicalPath(const String& uri)
{
@@ -183,7 +196,6 @@ SlangResult LanguageServer::parseNextMessage()
queueJSONCall(call);
return SLANG_OK;
}
-
}
case JSONRPCMessageType::Result:
{
@@ -223,7 +235,8 @@ SlangResult LanguageServer::parseNextMessage()
default:
{
return m_connection->sendError(
- JSONRPC::ErrorCode::InvalidRequest, m_connection->getCurrentMessageId());
+ JSONRPC::ErrorCode::InvalidRequest,
+ m_connection->getCurrentMessageId());
}
}
}
@@ -309,52 +322,53 @@ String getDeclSignatureString(DeclRef<Decl> declRef, WorkspaceVersion* version)
printer.getStringBuilder() << getDeclKindString(declRef);
printer.addDeclSignature(declRef);
auto printInitExpr = [&](Module* module, Type* declType, Expr* initExpr)
- {
- auto& sb = printer.getStringBuilder();
+ {
+ auto& sb = printer.getStringBuilder();
- if (auto litExpr = as<LiteralExpr>(initExpr))
- {
- if (litExpr->token.type != TokenType::Unknown)
- sb << " = " << litExpr->token.getContent();
- else if (auto intLit = as<IntegerLiteralExpr>(litExpr))
- sb << " = " << intLit->value;
- }
- else if (auto isTypeDecl = as<IsTypeExpr>(initExpr))
+ if (auto litExpr = as<LiteralExpr>(initExpr))
+ {
+ if (litExpr->token.type != TokenType::Unknown)
+ sb << " = " << litExpr->token.getContent();
+ else if (auto intLit = as<IntegerLiteralExpr>(litExpr))
+ sb << " = " << intLit->value;
+ }
+ else if (auto isTypeDecl = as<IsTypeExpr>(initExpr))
+ {
+ if (isTypeDecl->constantVal)
{
- if (isTypeDecl->constantVal)
- {
- sb << " = " << (isTypeDecl->constantVal->value ? "true" : "false");
- }
+ sb << " = " << (isTypeDecl->constantVal->value ? "true" : "false");
}
- else if (initExpr)
- {
- DiagnosticSink sink;
- SharedSemanticsContext semanticContext(version->linkage, module, &sink);
- SemanticsVisitor semanticsVisitor(&semanticContext);
- if (auto intVal = semanticsVisitor.tryFoldIntegerConstantExpression(
+ }
+ else if (initExpr)
+ {
+ DiagnosticSink sink;
+ SharedSemanticsContext semanticContext(version->linkage, module, &sink);
+ SemanticsVisitor semanticsVisitor(&semanticContext);
+ if (auto intVal = semanticsVisitor.tryFoldIntegerConstantExpression(
declRef.substitute(version->linkage->getASTBuilder(), initExpr),
- SemanticsVisitor::ConstantFoldingKind::LinkTime, nullptr))
+ SemanticsVisitor::ConstantFoldingKind::LinkTime,
+ nullptr))
+ {
+ if (auto constantInt = as<ConstantIntVal>(intVal))
{
- if (auto constantInt = as<ConstantIntVal>(intVal))
+ sb << " = ";
+ if (isBoolType(declType))
{
- sb << " = ";
- if (isBoolType(declType))
- {
- sb << (constantInt->getValue() ? "true" : "false");
- }
- else
- {
- sb << constantInt->getValue();
- }
+ sb << (constantInt->getValue() ? "true" : "false");
}
else
{
- sb << " = ";
- intVal->toText(sb);
+ sb << constantInt->getValue();
}
}
+ else
+ {
+ sb << " = ";
+ intVal->toText(sb);
+ }
}
- };
+ }
+ };
if (auto varDecl = as<VarDeclBase>(declRef.getDecl()))
{
if (!varDecl->findModifier<ConstModifier>() && !as<LetDecl>(declRef.getDecl()))
@@ -409,10 +423,12 @@ static String _formatDocumentation(String doc)
if (trimedLine.getLength() > 0 && trimedLine[0] == '[')
{
endOfParamName = trimedLine.indexOf(']') + 1;
- while (endOfParamName < trimedLine.getLength() && CharUtil::isWhitespace(trimedLine[endOfParamName]))
+ while (endOfParamName < trimedLine.getLength() &&
+ CharUtil::isWhitespace(trimedLine[endOfParamName]))
endOfParamName++;
}
- while (endOfParamName < trimedLine.getLength() && !CharUtil::isWhitespace(trimedLine[endOfParamName]))
+ while (endOfParamName < trimedLine.getLength() &&
+ !CharUtil::isWhitespace(trimedLine[endOfParamName]))
endOfParamName++;
if (isFirstParam)
{
@@ -509,8 +525,7 @@ HumaneSourceLoc getModuleLoc(SourceManager* manager, ContainerDecl* moduleDecl)
{
if (moduleDecl)
{
- if (moduleDecl->members.getCount() &&
- moduleDecl->members[0])
+ if (moduleDecl->members.getCount() && moduleDecl->members[0])
{
auto loc = moduleDecl->members[0]->loc;
if (loc.isValid())
@@ -526,7 +541,8 @@ HumaneSourceLoc getModuleLoc(SourceManager* manager, ContainerDecl* moduleDecl)
}
SlangResult LanguageServer::hover(
- const LanguageServerProtocol::HoverParams& args, const JSONValue& responseId)
+ const LanguageServerProtocol::HoverParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.hover(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -594,7 +610,8 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
if (numOverloads > 1)
{
sb << "\n +" << numOverloads - 1 << " overload";
- if (numOverloads > 2) sb << "s";
+ if (numOverloads > 2)
+ sb << "s";
}
};
@@ -602,16 +619,17 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
{
if (declRef.getDecl())
{
- sb << "```\n"
- << getDeclSignatureString(declRef, version)
- << "\n```\n";
-
+ sb << "```\n" << getDeclSignatureString(declRef, version) << "\n```\n";
+
_tryGetDocumentation(sb, version, declRef.getDecl());
if (auto funcDecl = as<FunctionDeclBase>(declRef.getDecl()))
{
DiagnosticSink sink;
- SharedSemanticsContext semanticContext(version->linkage, getModule(funcDecl), &sink);
+ SharedSemanticsContext semanticContext(
+ version->linkage,
+ getModule(funcDecl),
+ &sink);
SemanticsVisitor semanticsVisitor(&semanticContext);
auto assocDecls = semanticContext.getAssociatedDeclsForDecl(funcDecl);
@@ -675,11 +693,11 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
}
auto humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(
- declRef.getLoc(), SourceLocType::Actual);
+ declRef.getLoc(),
+ SourceLocType::Actual);
appendDefinitionLocation(sb, m_workspace, humaneLoc);
maybeAppendAdditionalOverloadsHint();
- auto nodeHumaneLoc =
- version->linkage->getSourceManager()->getHumaneLoc(leafNode->loc);
+ auto nodeHumaneLoc = version->linkage->getSourceManager()->getHumaneLoc(leafNode->loc);
doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
nodeHumaneLoc.line,
nodeHumaneLoc.column,
@@ -698,14 +716,21 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
}
if (name)
{
- hover.range.end.character = hover.range.start.character + (int)UTF8Util::calcUTF16CharCount(name->text.getUnownedSlice());
+ hover.range.end.character =
+ hover.range.start.character +
+ (int)UTF8Util::calcUTF16CharCount(name->text.getUnownedSlice());
}
}
};
auto fillLoc = [&](SourceLoc loc)
{
- auto humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(loc, SourceLocType::Actual);
- doc->oneBasedUTF8LocToZeroBasedUTF16Loc(humaneLoc.line, humaneLoc.column, hover.range.start.line, hover.range.start.character);
+ auto humaneLoc =
+ version->linkage->getSourceManager()->getHumaneLoc(loc, SourceLocType::Actual);
+ doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
+ humaneLoc.line,
+ humaneLoc.column,
+ hover.range.start.line,
+ hover.range.start.character);
doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
humaneLoc.line,
humaneLoc.column + doc->getTokenLength(humaneLoc.line, humaneLoc.column),
@@ -720,7 +745,9 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
{
if (expr->type)
{
- sb << "```\n" << expr->type->toString() << " this" << "\n```\n";
+ sb << "```\n"
+ << expr->type->toString() << " this"
+ << "\n```\n";
}
fillLoc(expr->loc);
}
@@ -749,9 +776,13 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
{
if (countOfExpr->sizedType)
{
- if (auto foldedVal = as<ConstantIntVal>(CountOfIntVal::tryFoldOrNull(version->linkage->getASTBuilder(), expr->type.type, countOfExpr->sizedType)))
+ if (auto foldedVal = as<ConstantIntVal>(CountOfIntVal::tryFoldOrNull(
+ version->linkage->getASTBuilder(),
+ expr->type.type,
+ countOfExpr->sizedType)))
{
- sb << "```\n" << "countof(";
+ sb << "```\n"
+ << "countof(";
countOfExpr->sizedType->toText(sb);
sb << ") = " << foldedVal->getValue() << "\n```\n";
fillLoc(expr->loc);
@@ -764,9 +795,7 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
String signature = getExprDeclSignature(expr, &documentation, nullptr);
if (signature.getLength() == 0)
return;
- sb << "```\n"
- << signature
- << "\n```\n";
+ sb << "```\n" << signature << "\n```\n";
sb << documentation;
maybeAppendAdditionalOverloadsHint();
fillLoc(expr->loc);
@@ -807,42 +836,64 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
}
else if (auto importDecl = as<ImportDecl>(leafNode))
{
- auto moduleLoc = getModuleLoc(version->linkage->getSourceManager(), importDecl->importedModuleDecl);
+ auto moduleLoc =
+ getModuleLoc(version->linkage->getSourceManager(), importDecl->importedModuleDecl);
if (moduleLoc.pathInfo.hasFoundPath())
{
String path = moduleLoc.pathInfo.foundPath;
Path::getCanonical(path, path);
sb << path;
auto humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(
- importDecl->startLoc, SourceLocType::Actual);
+ importDecl->startLoc,
+ SourceLocType::Actual);
Index utf16Line, utf16Col;
- doc->oneBasedUTF8LocToZeroBasedUTF16Loc(humaneLoc.line, humaneLoc.column, utf16Line, utf16Col);
+ doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
+ humaneLoc.line,
+ humaneLoc.column,
+ utf16Line,
+ utf16Col);
hover.range.start.line = (int)utf16Line;
hover.range.start.character = (int)utf16Col;
humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(
- importDecl->endLoc, SourceLocType::Actual);
- doc->oneBasedUTF8LocToZeroBasedUTF16Loc(humaneLoc.line, humaneLoc.column, utf16Line, utf16Col);
+ importDecl->endLoc,
+ SourceLocType::Actual);
+ doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
+ humaneLoc.line,
+ humaneLoc.column,
+ utf16Line,
+ utf16Col);
hover.range.end.line = (int)utf16Line;
hover.range.end.character = (int)utf16Col;
}
}
else if (auto includeDeclBase = as<IncludeDeclBase>(leafNode))
{
- auto moduleLoc = getModuleLoc(version->linkage->getSourceManager(), includeDeclBase->fileDecl);
+ auto moduleLoc =
+ getModuleLoc(version->linkage->getSourceManager(), includeDeclBase->fileDecl);
if (moduleLoc.pathInfo.hasFoundPath())
{
String path = moduleLoc.pathInfo.foundPath;
Path::getCanonical(path, path);
sb << path;
auto humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(
- includeDeclBase->startLoc, SourceLocType::Actual);
+ includeDeclBase->startLoc,
+ SourceLocType::Actual);
Index utf16Line, utf16Col;
- doc->oneBasedUTF8LocToZeroBasedUTF16Loc(humaneLoc.line, humaneLoc.column, utf16Line, utf16Col);
+ doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
+ humaneLoc.line,
+ humaneLoc.column,
+ utf16Line,
+ utf16Col);
hover.range.start.line = (int)utf16Line;
hover.range.start.character = (int)utf16Col;
humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(
- includeDeclBase->endLoc, SourceLocType::Actual);
- doc->oneBasedUTF8LocToZeroBasedUTF16Loc(humaneLoc.line, humaneLoc.column, utf16Line, utf16Col);
+ includeDeclBase->endLoc,
+ SourceLocType::Actual);
+ doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
+ humaneLoc.line,
+ humaneLoc.column,
+ utf16Line,
+ utf16Col);
hover.range.end.line = (int)utf16Line;
hover.range.end.character = (int)utf16Col;
}
@@ -854,7 +905,8 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
else if (auto attr = as<Attribute>(leafNode))
{
fillDeclRefHoverInfo(makeDeclRef(attr->attributeDecl), nullptr);
- hover.range.end.character = hover.range.start.character + (int)attr->originalIdentifierToken.getContentLength();
+ hover.range.end.character =
+ hover.range.start.character + (int)attr->originalIdentifierToken.getContentLength();
}
if (sb.getLength() == 0)
{
@@ -869,7 +921,8 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::hover(
}
SlangResult LanguageServer::gotoDefinition(
- const LanguageServerProtocol::DefinitionParams& args, const JSONValue& responseId)
+ const LanguageServerProtocol::DefinitionParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.gotoDefinition(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -927,11 +980,13 @@ LanguageServerResult<List<LanguageServerProtocol::Location>> LanguageServerCore:
if (declRefExpr->declRef.getDecl())
{
auto location = version->linkage->getSourceManager()->getHumaneLoc(
- declRefExpr->declRef.getNameLoc().isValid() ? declRefExpr->declRef.getNameLoc()
- : declRefExpr->declRef.getLoc(),
- SourceLocType::Actual);
+ declRefExpr->declRef.getNameLoc().isValid() ? declRefExpr->declRef.getNameLoc()
+ : declRefExpr->declRef.getLoc(),
+ SourceLocType::Actual);
auto name = declRefExpr->declRef.getName();
- locations.add(LocationResult{location, name ? (int)UTF8Util::calcUTF16CharCount(name->text.getUnownedSlice()) : 0});
+ locations.add(LocationResult{
+ location,
+ name ? (int)UTF8Util::calcUTF16CharCount(name->text.getUnownedSlice()) : 0});
}
}
else if (auto overloadedExpr = as<OverloadedExpr>(leafNode))
@@ -941,37 +996,45 @@ LanguageServerResult<List<LanguageServerProtocol::Location>> LanguageServerCore:
for (auto item : overloadedExpr->lookupResult2.items)
{
auto location = version->linkage->getSourceManager()->getHumaneLoc(
- item.declRef.getNameLoc(), SourceLocType::Actual);
+ item.declRef.getNameLoc(),
+ SourceLocType::Actual);
auto name = item.declRef.getName();
- locations.add(LocationResult{location, name ? (int)UTF8Util::calcUTF16CharCount(name->text.getUnownedSlice()) : 0});
+ locations.add(LocationResult{
+ location,
+ name ? (int)UTF8Util::calcUTF16CharCount(name->text.getUnownedSlice()) : 0});
}
}
- else
+ else
{
LookupResultItem& item = overloadedExpr->lookupResult2.item;
if (item.declRef.getDecl() != nullptr)
{
auto location = version->linkage->getSourceManager()->getHumaneLoc(
- item.declRef.getNameLoc(), SourceLocType::Actual);
+ item.declRef.getNameLoc(),
+ SourceLocType::Actual);
auto name = item.declRef.getName();
- locations.add(LocationResult{location, name ? (int)UTF8Util::calcUTF16CharCount(name->text.getUnownedSlice()) : 0});
+ locations.add(LocationResult{
+ location,
+ name ? (int)UTF8Util::calcUTF16CharCount(name->text.getUnownedSlice()) : 0});
}
}
}
else if (auto importDecl = as<ImportDecl>(leafNode))
{
- auto location = getModuleLoc(version->linkage->getSourceManager(), importDecl->importedModuleDecl);
+ auto location =
+ getModuleLoc(version->linkage->getSourceManager(), importDecl->importedModuleDecl);
if (location.pathInfo.hasFoundPath())
{
- locations.add(LocationResult{ location, 0 });
+ locations.add(LocationResult{location, 0});
}
}
else if (auto includeDeclBase = as<IncludeDeclBase>(leafNode))
{
- auto location = getModuleLoc(version->linkage->getSourceManager(), includeDeclBase->fileDecl);
+ auto location =
+ getModuleLoc(version->linkage->getSourceManager(), includeDeclBase->fileDecl);
if (location.pathInfo.hasFoundPath())
{
- locations.add(LocationResult{ location, 0 });
+ locations.add(LocationResult{location, 0});
}
}
if (locations.getCount() == 0)
@@ -1002,18 +1065,25 @@ LanguageServerResult<List<LanguageServerProtocol::Location>> LanguageServerCore:
}
}
-template <typename Func> struct Deferred
+template<typename Func>
+struct Deferred
{
Func f;
Deferred(const Func& func)
: f(func)
- {}
+ {
+ }
~Deferred() { f(); }
};
-template <typename Func> Deferred<Func> makeDeferred(const Func& f) { return Deferred<Func>(f); }
+template<typename Func>
+Deferred<Func> makeDeferred(const Func& f)
+{
+ return Deferred<Func>(f);
+}
SlangResult LanguageServer::completion(
- const LanguageServerProtocol::CompletionParams& args, const JSONValue& responseId)
+ const LanguageServerProtocol::CompletionParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.completion(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -1037,8 +1107,7 @@ LanguageServerResult<CompletionResult> LanguageServerCore::completion(
}
// Don't show completion at case label or after single '>' operator.
- if (args.context.triggerKind ==
- LanguageServerProtocol::kCompletionTriggerKindTriggerCharacter)
+ if (args.context.triggerKind == LanguageServerProtocol::kCompletionTriggerKindTriggerCharacter)
{
char requiredPrevChar = 0;
if (args.context.triggerCharacter == ":")
@@ -1050,7 +1119,8 @@ LanguageServerResult<CompletionResult> LanguageServerCore::completion(
// Check if the previous character is the required character (':' or '-'
auto line = doc->getLine((Int)args.position.line + 1);
auto prevCharPos = args.position.character - 2;
- if (prevCharPos >= 0 && prevCharPos < line.getLength() && line[prevCharPos] != requiredPrevChar)
+ if (prevCharPos >= 0 && prevCharPos < line.getLength() &&
+ line[prevCharPos] != requiredPrevChar)
{
return std::nullopt;
}
@@ -1059,7 +1129,10 @@ LanguageServerResult<CompletionResult> LanguageServerCore::completion(
Index utf8Line, utf8Col;
doc->zeroBasedUTF16LocToOneBasedUTF8Loc(
- args.position.line, args.position.character, utf8Line, utf8Col);
+ args.position.line,
+ args.position.character,
+ utf8Line,
+ utf8Col);
auto cursorOffset = doc->getOffset(utf8Line, utf8Col);
if (cursorOffset == -1 || doc->getText().getLength() == 0)
{
@@ -1074,7 +1147,8 @@ LanguageServerResult<CompletionResult> LanguageServerCore::completion(
}
// Never show suggestions when the user is typing a number.
- if (cursorOffset + 1 >= 0 && cursorOffset + 1 < doc->getText().getLength() && CharUtil::isDigit(doc->getText()[cursorOffset + 1]))
+ if (cursorOffset + 1 >= 0 && cursorOffset + 1 < doc->getText().getLength() &&
+ CharUtil::isDigit(doc->getText()[cursorOffset + 1]))
{
return std::nullopt;
}
@@ -1097,9 +1171,11 @@ LanguageServerResult<CompletionResult> LanguageServerCore::completion(
context.col = utf8Col;
context.commitCharacterBehavior = m_commitCharacterBehavior;
if (args.context.triggerKind == kCompletionTriggerKindTriggerCharacter &&
- (args.context.triggerCharacter == " " || args.context.triggerCharacter == "[" || args.context.triggerCharacter == "("))
+ (args.context.triggerCharacter == " " || args.context.triggerCharacter == "[" ||
+ args.context.triggerCharacter == "("))
{
- // Never use commit character if completion request is triggerred by these characters to prevent annoyance.
+ // Never use commit character if completion request is triggerred by these characters to
+ // prevent annoyance.
context.commitCharacterBehavior = CommitCharacterBehavior::Disabled;
}
@@ -1107,7 +1183,7 @@ LanguageServerResult<CompletionResult> LanguageServerCore::completion(
SLANG_LS_RETURN_ON_SUCCESS(context.tryCompleteImport());
if (args.context.triggerKind ==
- LanguageServerProtocol::kCompletionTriggerKindTriggerCharacter &&
+ LanguageServerProtocol::kCompletionTriggerKindTriggerCharacter &&
(args.context.triggerCharacter == "\"" || args.context.triggerCharacter == "/"))
{
// Trigger characters '"' and '/' are for include only.
@@ -1119,7 +1195,7 @@ LanguageServerResult<CompletionResult> LanguageServerCore::completion(
auto originalText = doc->getText();
StringBuilder newText;
newText << originalText.getUnownedSlice().head(cursorOffset + 1) << "#?"
- << originalText.getUnownedSlice().tail(cursorOffset + 1);
+ << originalText.getUnownedSlice().tail(cursorOffset + 1);
doc->setText(newText.produceString());
auto restoreDocText = makeDeferred([&]() { doc->setText(originalText); });
@@ -1134,7 +1210,7 @@ LanguageServerResult<CompletionResult> LanguageServerCore::completion(
// Don't generate completion suggestions after typing '['.
if (args.context.triggerKind ==
- LanguageServerProtocol::kCompletionTriggerKindTriggerCharacter &&
+ LanguageServerProtocol::kCompletionTriggerKindTriggerCharacter &&
args.context.triggerCharacter == "[")
{
return std::nullopt;
@@ -1146,7 +1222,9 @@ LanguageServerResult<CompletionResult> LanguageServerCore::completion(
}
SlangResult LanguageServer::completionResolve(
- const LanguageServerProtocol::CompletionItem& args, const LanguageServerProtocol::TextEditCompletionItem& editItem, const JSONValue& responseId)
+ const LanguageServerProtocol::CompletionItem& args,
+ const LanguageServerProtocol::TextEditCompletionItem& editItem,
+ const JSONValue& responseId)
{
auto result = m_core.completionResolve(args, editItem);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -1159,7 +1237,8 @@ SlangResult LanguageServer::completionResolve(
}
LanguageServerResult<LanguageServerProtocol::CompletionItem> LanguageServerCore::completionResolve(
- const LanguageServerProtocol::CompletionItem& args, const LanguageServerProtocol::TextEditCompletionItem& editItem)
+ const LanguageServerProtocol::CompletionItem& args,
+ const LanguageServerProtocol::TextEditCompletionItem& editItem)
{
if (args.data.getLength() == 0)
{
@@ -1192,7 +1271,8 @@ LanguageServerResult<LanguageServerProtocol::CompletionItem> LanguageServerCore:
}
SlangResult LanguageServer::semanticTokens(
- const LanguageServerProtocol::SemanticTokensParams& args, const JSONValue& responseId)
+ const LanguageServerProtocol::SemanticTokensParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.semanticTokens(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -1224,14 +1304,21 @@ LanguageServerResult<LanguageServerProtocol::SemanticTokens> LanguageServerCore:
return std::nullopt;
}
- auto tokens = getSemanticTokens(version->linkage, parsedModule, canonicalPath.getUnownedSlice(), doc.Ptr());
+ auto tokens = getSemanticTokens(
+ version->linkage,
+ parsedModule,
+ canonicalPath.getUnownedSlice(),
+ doc.Ptr());
for (auto& token : tokens)
{
Index line, col;
doc->oneBasedUTF8LocToZeroBasedUTF16Loc(token.line, token.col, line, col);
Index lineEnd, colEnd;
doc->oneBasedUTF8LocToZeroBasedUTF16Loc(
- token.line, token.col + token.length, lineEnd, colEnd);
+ token.line,
+ token.col + token.length,
+ lineEnd,
+ colEnd);
token.line = (int)line;
token.col = (int)col;
token.length = (int)(colEnd - col);
@@ -1242,7 +1329,10 @@ LanguageServerResult<LanguageServerProtocol::SemanticTokens> LanguageServerCore:
return response;
}
-String LanguageServerCore::getExprDeclSignature(Expr* expr, String* outDocumentation, List<Slang::Range<Index>>* outParamRanges)
+String LanguageServerCore::getExprDeclSignature(
+ Expr* expr,
+ String* outDocumentation,
+ List<Slang::Range<Index>>* outParamRanges)
{
if (auto declRefExpr = as<DeclRefExpr>(expr))
{
@@ -1267,7 +1357,7 @@ String LanguageServerCore::getExprDeclSignature(Expr* expr, String* outDocumenta
ASTPrinter printer(
version->linkage->getASTBuilder(),
ASTPrinter::OptionFlag::ParamNames | ASTPrinter::OptionFlag::NoInternalKeywords |
- ASTPrinter::OptionFlag::SimplifiedBuiltinType);
+ ASTPrinter::OptionFlag::SimplifiedBuiltinType);
printer.addDeclKindPrefix(declRefExpr->declRef.getDecl());
auto inner = higherOrderExpr;
@@ -1294,7 +1384,8 @@ String LanguageServerCore::getExprDeclSignature(Expr* expr, String* outDocumenta
{
if (higherOrderExpr->newParameterNames[paramIndex])
{
- printer.getStringBuilder() << higherOrderExpr->newParameterNames[paramIndex]->text << ": ";
+ printer.getStringBuilder()
+ << higherOrderExpr->newParameterNames[paramIndex]->text << ": ";
}
}
printer.addType(param);
@@ -1310,7 +1401,9 @@ String LanguageServerCore::getExprDeclSignature(Expr* expr, String* outDocumenta
if (outDocumentation)
{
StringBuilder docSB;
- auto humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(declRefExpr->declRef.getLoc(), SourceLocType::Actual);
+ auto humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(
+ declRefExpr->declRef.getLoc(),
+ SourceLocType::Actual);
_tryGetDocumentation(docSB, version, declRefExpr->declRef.getDecl());
appendDefinitionLocation(docSB, m_workspace, humaneLoc);
*outDocumentation = docSB.produceString();
@@ -1319,7 +1412,10 @@ String LanguageServerCore::getExprDeclSignature(Expr* expr, String* outDocumenta
return printer.getString();
}
-String LanguageServerCore::getDeclRefSignature(DeclRef<Decl> declRef, String* outDocumentation, List<Slang::Range<Index>>* outParamRanges)
+String LanguageServerCore::getDeclRefSignature(
+ DeclRef<Decl> declRef,
+ String* outDocumentation,
+ List<Slang::Range<Index>>* outParamRanges)
{
auto version = m_workspace->getCurrentVersion();
SLANG_AST_BUILDER_RAII(version->linkage->getASTBuilder());
@@ -1327,7 +1423,7 @@ String LanguageServerCore::getDeclRefSignature(DeclRef<Decl> declRef, String* ou
ASTPrinter printer(
version->linkage->getASTBuilder(),
ASTPrinter::OptionFlag::ParamNames | ASTPrinter::OptionFlag::NoInternalKeywords |
- ASTPrinter::OptionFlag::SimplifiedBuiltinType);
+ ASTPrinter::OptionFlag::SimplifiedBuiltinType);
printer.addDeclKindPrefix(declRef.getDecl());
printer.addDeclPath(declRef);
@@ -1337,7 +1433,9 @@ String LanguageServerCore::getDeclRefSignature(DeclRef<Decl> declRef, String* ou
if (outDocumentation)
{
StringBuilder docSB;
- auto humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(declRef.getLoc(), SourceLocType::Actual);
+ auto humaneLoc = version->linkage->getSourceManager()->getHumaneLoc(
+ declRef.getLoc(),
+ SourceLocType::Actual);
_tryGetDocumentation(docSB, version, declRef.getDecl());
appendDefinitionLocation(docSB, m_workspace, humaneLoc);
*outDocumentation = docSB.produceString();
@@ -1346,7 +1444,8 @@ String LanguageServerCore::getDeclRefSignature(DeclRef<Decl> declRef, String* ou
}
SlangResult LanguageServer::signatureHelp(
- const LanguageServerProtocol::SignatureHelpParams& args, const JSONValue& responseId)
+ const LanguageServerProtocol::SignatureHelpParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.signatureHelp(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -1404,9 +1503,12 @@ LanguageServerResult<LanguageServerProtocol::SignatureHelp> LanguageServerCore::
// This allows us to skip the invoke expr nodes for operators/implcit casts.
if (expr->argumentDelimeterLocs.getCount())
{
- auto start = Loc::fromSourceLoc(version->linkage->getSourceManager(), expr->argumentDelimeterLocs.getFirst());
+ auto start = Loc::fromSourceLoc(
+ version->linkage->getSourceManager(),
+ expr->argumentDelimeterLocs.getFirst());
auto end = Loc::fromSourceLoc(
- version->linkage->getSourceManager(), expr->argumentDelimeterLocs.getLast());
+ version->linkage->getSourceManager(),
+ expr->argumentDelimeterLocs.getLast());
if (start < currentLoc && currentLoc <= end)
{
appExpr = expr;
@@ -1496,7 +1598,7 @@ LanguageServerResult<LanguageServerProtocol::SignatureHelp> LanguageServerCore::
ASTPrinter printer(
version->linkage->getASTBuilder(),
ASTPrinter::OptionFlag::ParamNames | ASTPrinter::OptionFlag::NoInternalKeywords |
- ASTPrinter::OptionFlag::SimplifiedBuiltinType);
+ ASTPrinter::OptionFlag::SimplifiedBuiltinType);
printer.getStringBuilder() << "func (";
bool isFirst = true;
@@ -1529,7 +1631,8 @@ LanguageServerResult<LanguageServerProtocol::SignatureHelp> LanguageServerCore::
if (auto aggDeclRef = as<AggTypeDecl>(declRefExpr->declRef))
{
// Look for initializers
- for (auto member : getMembersOfType<ConstructorDecl>(version->linkage->getASTBuilder(), aggDeclRef))
+ for (auto member :
+ getMembersOfType<ConstructorDecl>(version->linkage->getASTBuilder(), aggDeclRef))
{
addDeclRef(member);
}
@@ -1566,9 +1669,11 @@ LanguageServerResult<LanguageServerProtocol::SignatureHelp> LanguageServerCore::
for (int i = 1; i < appExpr->argumentDelimeterLocs.getCount(); i++)
{
auto delimLoc = version->linkage->getSourceManager()->getHumaneLoc(
- appExpr->argumentDelimeterLocs[i], SourceLocType::Actual);
+ appExpr->argumentDelimeterLocs[i],
+ SourceLocType::Actual);
if (delimLoc.line > args.position.line + 1 ||
- delimLoc.line == args.position.line + 1 && delimLoc.column >= args.position.character + 1)
+ delimLoc.line == args.position.line + 1 &&
+ delimLoc.column >= args.position.character + 1)
{
response.activeParameter = i - 1;
break;
@@ -1579,7 +1684,8 @@ LanguageServerResult<LanguageServerProtocol::SignatureHelp> LanguageServerCore::
}
SlangResult LanguageServer::documentSymbol(
- const LanguageServerProtocol::DocumentSymbolParams& args, const JSONValue& responseId)
+ const LanguageServerProtocol::DocumentSymbolParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.documentSymbol(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -1591,8 +1697,8 @@ SlangResult LanguageServer::documentSymbol(
return SLANG_OK;
}
-LanguageServerResult<List<LanguageServerProtocol::DocumentSymbol>> LanguageServerCore::documentSymbol(
- const LanguageServerProtocol::DocumentSymbolParams& args)
+LanguageServerResult<List<LanguageServerProtocol::DocumentSymbol>> LanguageServerCore::
+ documentSymbol(const LanguageServerProtocol::DocumentSymbolParams& args)
{
String canonicalPath = uriToCanonicalPath(args.textDocument.uri);
RefPtr<DocumentVersion> doc;
@@ -1608,11 +1714,17 @@ LanguageServerResult<List<LanguageServerProtocol::DocumentSymbol>> LanguageServe
{
return std::nullopt;
}
- List<DocumentSymbol> symbols = getDocumentSymbols(version->linkage, parsedModule, canonicalPath.getUnownedSlice(), doc.Ptr());
+ List<DocumentSymbol> symbols = getDocumentSymbols(
+ version->linkage,
+ parsedModule,
+ canonicalPath.getUnownedSlice(),
+ doc.Ptr());
return symbols;
}
-SlangResult LanguageServer::inlayHint(const LanguageServerProtocol::InlayHintParams& args, const JSONValue& responseId)
+SlangResult LanguageServer::inlayHint(
+ const LanguageServerProtocol::InlayHintParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.inlayHint(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -1624,7 +1736,8 @@ SlangResult LanguageServer::inlayHint(const LanguageServerProtocol::InlayHintPar
return SLANG_OK;
}
-LanguageServerResult<List<LanguageServerProtocol::InlayHint>> LanguageServerCore::inlayHint(const LanguageServerProtocol::InlayHintParams& args)
+LanguageServerResult<List<LanguageServerProtocol::InlayHint>> LanguageServerCore::inlayHint(
+ const LanguageServerProtocol::InlayHintParams& args)
{
String canonicalPath = uriToCanonicalPath(args.textDocument.uri);
RefPtr<DocumentVersion> doc;
@@ -1672,7 +1785,9 @@ List<LanguageServerProtocol::TextEdit> translateTextEdits(DocumentVersion* doc,
return result;
}
-SlangResult LanguageServer::formatting(const LanguageServerProtocol::DocumentFormattingParams& args, const JSONValue& responseId)
+SlangResult LanguageServer::formatting(
+ const LanguageServerProtocol::DocumentFormattingParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.formatting(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -1697,13 +1812,17 @@ LanguageServerResult<List<LanguageServerProtocol::TextEdit>> LanguageServerCore:
m_formatOptions.clangFormatLocation = findClangFormatTool();
auto options = getFormatOptions(m_workspace, m_formatOptions);
options.fileName = canonicalPath;
- List<TextRange> exclusionRange = extractFormattingExclusionRanges(doc->getText().getUnownedSlice());
- auto edits = formatSource(doc->getText().getUnownedSlice(), -1, -1, -1, exclusionRange, options);
+ List<TextRange> exclusionRange =
+ extractFormattingExclusionRanges(doc->getText().getUnownedSlice());
+ auto edits =
+ formatSource(doc->getText().getUnownedSlice(), -1, -1, -1, exclusionRange, options);
auto textEdits = translateTextEdits(doc, edits);
return textEdits;
}
-SlangResult LanguageServer::rangeFormatting(const LanguageServerProtocol::DocumentRangeFormattingParams& args, const JSONValue& responseId)
+SlangResult LanguageServer::rangeFormatting(
+ const LanguageServerProtocol::DocumentRangeFormattingParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.rangeFormatting(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -1725,20 +1844,33 @@ LanguageServerResult<List<LanguageServerProtocol::TextEdit>> LanguageServerCore:
return std::nullopt;
}
Index endLine, endCol;
- doc->zeroBasedUTF16LocToOneBasedUTF8Loc(args.range.end.line, args.range.end.character, endLine, endCol);
+ doc->zeroBasedUTF16LocToOneBasedUTF8Loc(
+ args.range.end.line,
+ args.range.end.character,
+ endLine,
+ endCol);
Index endOffset = doc->getOffset(endLine, endCol);
if (m_formatOptions.clangFormatLocation.getLength() == 0)
m_formatOptions.clangFormatLocation = findClangFormatTool();
auto options = getFormatOptions(m_workspace, m_formatOptions);
if (!m_formatOptions.allowLineBreakInRangeFormatting)
options.behavior = FormatBehavior::PreserveLineBreak;
- List<TextRange> exclusionRange = extractFormattingExclusionRanges(doc->getText().getUnownedSlice());
- auto edits = formatSource(doc->getText().getUnownedSlice(), args.range.start.line, args.range.end.line, endOffset, exclusionRange, options);
+ List<TextRange> exclusionRange =
+ extractFormattingExclusionRanges(doc->getText().getUnownedSlice());
+ auto edits = formatSource(
+ doc->getText().getUnownedSlice(),
+ args.range.start.line,
+ args.range.end.line,
+ endOffset,
+ exclusionRange,
+ options);
auto textEdits = translateTextEdits(doc, edits);
return textEdits;
}
-SlangResult LanguageServer::onTypeFormatting(const LanguageServerProtocol::DocumentOnTypeFormattingParams& args, const JSONValue& responseId)
+SlangResult LanguageServer::onTypeFormatting(
+ const LanguageServerProtocol::DocumentOnTypeFormattingParams& args,
+ const JSONValue& responseId)
{
auto result = m_core.onTypeFormatting(args);
if (SLANG_FAILED(result.returnCode) || result.isNull)
@@ -1750,7 +1882,7 @@ SlangResult LanguageServer::onTypeFormatting(const LanguageServerProtocol::Docum
return SLANG_OK;
}
-LanguageServerResult<List<LanguageServerProtocol::TextEdit>> LanguageServerCore::onTypeFormatting(
+LanguageServerResult<List<LanguageServerProtocol::TextEdit>> LanguageServerCore::onTypeFormatting(
const LanguageServerProtocol::DocumentOnTypeFormattingParams& args)
{
String canonicalPath = uriToCanonicalPath(args.textDocument.uri);
@@ -1771,15 +1903,23 @@ LanguageServerResult<List<LanguageServerProtocol::TextEdit>> LanguageServerCore
auto options = getFormatOptions(m_workspace, m_formatOptions);
if (!m_formatOptions.allowLineBreakInOnTypeFormatting)
options.behavior = FormatBehavior::PreserveLineBreak;
- List<TextRange> exclusionRange = extractFormattingExclusionRanges(doc->getText().getUnownedSlice());
- auto edits = formatSource(doc->getText().getUnownedSlice(), args.position.line, args.position.line, cursorOffset, exclusionRange, options);
+ List<TextRange> exclusionRange =
+ extractFormattingExclusionRanges(doc->getText().getUnownedSlice());
+ auto edits = formatSource(
+ doc->getText().getUnownedSlice(),
+ args.position.line,
+ args.position.line,
+ cursorOffset,
+ exclusionRange,
+ options);
auto textEdits = translateTextEdits(doc, edits);
return textEdits;
}
void LanguageServer::publishDiagnostics()
{
- if (std::chrono::system_clock::now() - m_lastDiagnosticUpdateTime < std::chrono::milliseconds(1000))
+ if (std::chrono::system_clock::now() - m_lastDiagnosticUpdateTime <
+ std::chrono::milliseconds(1000))
{
return;
}
@@ -1823,9 +1963,9 @@ void LanguageServer::publishDiagnostics()
void sendRefreshRequests(JSONRPCConnection* connection)
{
connection->sendCall(
- UnownedStringSlice("workspace/semanticTokens/refresh"), JSONValue::makeInt(0));
- connection->sendCall(
- UnownedStringSlice("workspace/inlayHint/refresh"), JSONValue::makeInt(0));
+ UnownedStringSlice("workspace/semanticTokens/refresh"),
+ JSONValue::makeInt(0));
+ connection->sendCall(UnownedStringSlice("workspace/inlayHint/refresh"), JSONValue::makeInt(0));
}
void LanguageServer::updatePredefinedMacros(const JSONValue& macros)
@@ -1904,7 +2044,12 @@ void LanguageServer::updateCommitCharacters(const JSONValue& jsonValue)
}
}
-void LanguageServer::updateFormattingOptions(const JSONValue& clangFormatLoc, const JSONValue& clangFormatStyle, const JSONValue& clangFormatFallbackStyle, const JSONValue& allowLineBreakOnType, const JSONValue& allowLineBreakInRange)
+void LanguageServer::updateFormattingOptions(
+ const JSONValue& clangFormatLoc,
+ const JSONValue& clangFormatStyle,
+ const JSONValue& clangFormatFallbackStyle,
+ const JSONValue& allowLineBreakOnType,
+ const JSONValue& allowLineBreakInRange)
{
auto container = m_connection->getContainer();
JSONToNativeConverter converter(container, &m_typeMap, m_connection->getSink());
@@ -1915,14 +2060,20 @@ void LanguageServer::updateFormattingOptions(const JSONValue& clangFormatLoc, co
if (clangFormatFallbackStyle.isValid())
converter.convert(clangFormatFallbackStyle, &m_core.m_formatOptions.fallbackStyle);
if (allowLineBreakOnType.isValid())
- converter.convert(allowLineBreakOnType, &m_core.m_formatOptions.allowLineBreakInOnTypeFormatting);
+ converter.convert(
+ allowLineBreakOnType,
+ &m_core.m_formatOptions.allowLineBreakInOnTypeFormatting);
if (allowLineBreakInRange.isValid())
- converter.convert(allowLineBreakInRange, &m_core.m_formatOptions.allowLineBreakInRangeFormatting);
+ converter.convert(
+ allowLineBreakInRange,
+ &m_core.m_formatOptions.allowLineBreakInRangeFormatting);
if (m_core.m_formatOptions.style.getLength() == 0)
m_core.m_formatOptions.style = Slang::FormatOptions().style;
}
-void LanguageServer::updateInlayHintOptions(const JSONValue& deducedTypes, const JSONValue& parameterNames)
+void LanguageServer::updateInlayHintOptions(
+ const JSONValue& deducedTypes,
+ const JSONValue& parameterNames)
{
auto container = m_connection->getContainer();
JSONToNativeConverter converter(container, &m_typeMap, m_connection->getSink());
@@ -1930,10 +2081,12 @@ void LanguageServer::updateInlayHintOptions(const JSONValue& deducedTypes, const
bool showParameterNames = false;
converter.convert(deducedTypes, &showDeducedType);
converter.convert(parameterNames, &showParameterNames);
- if (showDeducedType != m_core.m_inlayHintOptions.showDeducedType || showParameterNames != m_core.m_inlayHintOptions.showParameterNames)
+ if (showDeducedType != m_core.m_inlayHintOptions.showDeducedType ||
+ showParameterNames != m_core.m_inlayHintOptions.showParameterNames)
{
m_connection->sendCall(
- UnownedStringSlice("workspace/inlayHint/refresh"), JSONValue::makeInt(0));
+ UnownedStringSlice("workspace/inlayHint/refresh"),
+ JSONValue::makeInt(0));
}
m_core.m_inlayHintOptions.showDeducedType = showDeducedType;
m_core.m_inlayHintOptions.showParameterNames = showParameterNames;
@@ -2000,7 +2153,9 @@ void LanguageServer::registerCapability(const char* methodName)
reg.id = reg.method;
args.registrations.add(reg);
m_connection->sendCall(
- UnownedStringSlice("client/registerCapability"), &args, JSONValue::makeInt(999));
+ UnownedStringSlice("client/registerCapability"),
+ &args,
+ JSONValue::makeInt(999));
}
void LanguageServer::logMessage(int type, String message)
@@ -2025,7 +2180,10 @@ FormatOptions LanguageServerCore::getFormatOptions(Workspace* workspace, FormatO
}
LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::tryGetMacroHoverInfo(
- WorkspaceVersion* version, DocumentVersion* doc, Index line, Index col)
+ WorkspaceVersion* version,
+ DocumentVersion* doc,
+ Index line,
+ Index col)
{
Index startOffset = 0;
auto identifier = doc->peekIdentifier(line, col, startOffset);
@@ -2075,7 +2233,10 @@ LanguageServerResult<LanguageServerProtocol::Hover> LanguageServerCore::tryGetMa
}
LanguageServerResult<List<Location>> LanguageServerCore::tryGotoMacroDefinition(
- WorkspaceVersion* version, DocumentVersion* doc, Index line, Index col)
+ WorkspaceVersion* version,
+ DocumentVersion* doc,
+ Index line,
+ Index col)
{
Index startOffset = 0;
auto identifier = doc->peekIdentifier(line, col, startOffset);
@@ -2100,7 +2261,9 @@ LanguageServerResult<List<Location>> LanguageServerCore::tryGotoMacroDefinition(
}
LanguageServerResult<List<Location>> LanguageServerCore::tryGotoFileInclude(
- WorkspaceVersion* version, DocumentVersion* doc, Index line)
+ WorkspaceVersion* version,
+ DocumentVersion* doc,
+ Index line)
{
auto lineContent = doc->getLine(line).trim();
if (!lineContent.startsWith("#") || lineContent.indexOf(UnownedStringSlice("include")) == -1)
@@ -2169,7 +2332,11 @@ SlangResult LanguageServer::queueJSONCall(JSONRPCCall call)
else if (call.method == SemanticTokensParams::methodName)
{
SemanticTokensParams args;
- SLANG_RETURN_ON_FAIL(m_connection->checkArrayObjectWrap( call.params, GetRttiInfo<SemanticTokensParams>::get(), &args, call.id ));
+ SLANG_RETURN_ON_FAIL(m_connection->checkArrayObjectWrap(
+ call.params,
+ GetRttiInfo<SemanticTokensParams>::get(),
+ &args,
+ call.id));
cmd.semanticTokenArgs = args;
}
else if (call.method == SignatureHelpParams::methodName)
@@ -2184,13 +2351,18 @@ SlangResult LanguageServer::queueJSONCall(JSONRPCCall call)
SLANG_RETURN_ON_FAIL(m_connection->toNativeArgsOrSendError(call.params, &args, call.id));
cmd.completionResolveArgs = args;
Slang::LanguageServerProtocol::TextEditCompletionItem editArgs;
- SLANG_RETURN_ON_FAIL(m_connection->toNativeArgsOrSendError(call.params, &editArgs, call.id));
+ SLANG_RETURN_ON_FAIL(
+ m_connection->toNativeArgsOrSendError(call.params, &editArgs, call.id));
cmd.textEditCompletionResolveArgs = editArgs;
}
else if (call.method == DocumentSymbolParams::methodName)
{
DocumentSymbolParams args;
- SLANG_RETURN_ON_FAIL(m_connection->checkArrayObjectWrap( call.params, GetRttiInfo<DocumentSymbolParams>::get(), &args, call.id ));
+ SLANG_RETURN_ON_FAIL(m_connection->checkArrayObjectWrap(
+ call.params,
+ GetRttiInfo<DocumentSymbolParams>::get(),
+ &args,
+ call.id));
cmd.documentSymbolArgs = args;
}
else if (call.method == DocumentFormattingParams::methodName)
@@ -2287,7 +2459,10 @@ SlangResult LanguageServer::runCommand(Command& call)
}
else if (call.method == "completionItem/resolve")
{
- return completionResolve(call.completionResolveArgs.get(), call.textEditCompletionResolveArgs.get(), call.id);
+ return completionResolve(
+ call.completionResolveArgs.get(),
+ call.textEditCompletionResolveArgs.get(),
+ call.id);
}
else if (call.method == DocumentSymbolParams::methodName)
{
@@ -2345,7 +2520,8 @@ void LanguageServer::processCommands()
const int kErrorRequestCanceled = -32800;
for (auto& cmd : commands)
{
- if (cmd.id.getKind() == JSONValue::Kind::Integer && canceledIDs.contains(cmd.id.asInteger()))
+ if (cmd.id.getKind() == JSONValue::Kind::Integer &&
+ canceledIDs.contains(cmd.id.asInteger()))
{
m_connection->sendError((JSONRPC::ErrorCode)kErrorRequestCanceled, cmd.id);
}
@@ -2410,8 +2586,8 @@ void LanguageServer::updateConfigFromJSON(const JSONValue& jsonVal)
return;
auto obj = m_connection->getContainer()->getObject(jsonVal);
if (obj.getCount() == 1 &&
- (m_connection->getContainer()->getStringFromKey(obj[0].key) == "settings"
- || m_connection->getContainer()->getStringFromKey(obj[0].key) == "RootElement"))
+ (m_connection->getContainer()->getStringFromKey(obj[0].key) == "settings" ||
+ m_connection->getContainer()->getStringFromKey(obj[0].key) == "RootElement"))
{
updateConfigFromJSON(obj[0].value);
return;
@@ -2445,7 +2621,7 @@ void LanguageServer::updateConfigFromJSON(const JSONValue& jsonVal)
}
else if (key == "slang.format.allowLineBreakChangesInOnTypeFormatting")
{
- updateFormattingOptions(JSONValue(), JSONValue(), JSONValue(), kv.value, JSONValue());
+ updateFormattingOptions(JSONValue(), JSONValue(), JSONValue(), kv.value, JSONValue());
}
else if (key == "slang.format.allowLineBreakChangesInRangeFormatting")
{
@@ -2466,7 +2642,7 @@ SlangResult LanguageServer::execute()
{
m_connection = new JSONRPCConnection();
m_connection->initWithStdStreams();
-
+
while (m_connection->isActive() && !m_quit)
{
// Consume all messages first.