summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-language-server.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-10-06 14:03:18 -0700
committerGitHub <noreply@github.com>2023-10-06 14:03:18 -0700
commit17c7163c2ae8fc290e70b43d8700b68ef18b1ee1 (patch)
tree09df040039fb1221810f956bb83871430cbac47f /source/slang/slang-language-server.cpp
parent4547125ce945140dc10542e9606b225dd06159b8 (diff)
Small type system fixes. (#3265)
Diffstat (limited to 'source/slang/slang-language-server.cpp')
-rw-r--r--source/slang/slang-language-server.cpp22
1 files changed, 18 insertions, 4 deletions
diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp
index 3a21fa278..cea5d0151 100644
--- a/source/slang/slang-language-server.cpp
+++ b/source/slang/slang-language-server.cpp
@@ -1469,9 +1469,10 @@ SlangResult LanguageServer::formatting(const LanguageServerProtocol::DocumentFor
}
if (m_formatOptions.clangFormatLocation.getLength() == 0)
m_formatOptions.clangFormatLocation = findClangFormatTool();
- m_formatOptions.fileName = canonicalPath;
+ 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, m_formatOptions);
+ auto edits = formatSource(doc->getText().getUnownedSlice(), -1, -1, -1, exclusionRange, options);
auto textEdits = translateTextEdits(doc, edits);
m_connection->sendResult(&textEdits, responseId);
return SLANG_OK;
@@ -1491,7 +1492,7 @@ SlangResult LanguageServer::rangeFormatting(const LanguageServerProtocol::Docume
Index endOffset = doc->getOffset(endLine, endCol);
if (m_formatOptions.clangFormatLocation.getLength() == 0)
m_formatOptions.clangFormatLocation = findClangFormatTool();
- auto options = m_formatOptions;
+ auto options = getFormatOptions(m_workspace, m_formatOptions);
if (!m_formatOptions.allowLineBreakInRangeFormatting)
options.behavior = FormatBehavior::PreserveLineBreak;
List<TextRange> exclusionRange = extractFormattingExclusionRanges(doc->getText().getUnownedSlice());
@@ -1520,7 +1521,7 @@ SlangResult LanguageServer::onTypeFormatting(const LanguageServerProtocol::Docum
Index line, col;
doc->zeroBasedUTF16LocToOneBasedUTF8Loc(args.position.line, args.position.character, line, col);
auto cursorOffset = doc->getOffset(line, col);
- auto options = m_formatOptions;
+ auto options = getFormatOptions(m_workspace, m_formatOptions);
if (!m_formatOptions.allowLineBreakInOnTypeFormatting)
options.behavior = FormatBehavior::PreserveLineBreak;
List<TextRange> exclusionRange = extractFormattingExclusionRanges(doc->getText().getUnownedSlice());
@@ -1760,6 +1761,19 @@ void LanguageServer::logMessage(int type, String message)
m_connection->sendCall(LanguageServerProtocol::LogMessageParams::methodName, &args);
}
+FormatOptions LanguageServer::getFormatOptions(Workspace* workspace, FormatOptions inOptions)
+{
+ FormatOptions result = inOptions;
+ if (workspace->rootDirectories.getCount())
+ {
+ result.clangFormatLocation = StringUtil::replaceAll(
+ result.clangFormatLocation.getUnownedSlice(),
+ toSlice("${workspaceFolder}"),
+ workspace->rootDirectories.getFirst().getUnownedSlice());
+ }
+ return result;
+}
+
SlangResult LanguageServer::tryGetMacroHoverInfo(
WorkspaceVersion* version, DocumentVersion* doc, Index line, Index col, JSONValue responseId)
{