summaryrefslogtreecommitdiffstats
path: root/source/slang/slang-language-server.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2023-12-05 10:06:19 -0800
committerGitHub <noreply@github.com>2023-12-05 10:06:19 -0800
commit1050e0eb96d6c8e7a6cfb253458155e1014625c3 (patch)
treece6c3cbde591759fa2fe2aeb05cb132e50a9a419 /source/slang/slang-language-server.cpp
parent4fb3b10b81cf8c976ebd1ebb7fcde7708f022957 (diff)
Support `include` for pulling file into the current module. (#3377)
* Support `include` for pulling file into the current module. * Add auto-completion, hover info and goto-def support. * Disable warning for missing `module` declaration for now. --------- Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-language-server.cpp')
-rw-r--r--source/slang/slang-language-server.cpp31
1 files changed, 30 insertions, 1 deletions
diff --git a/source/slang/slang-language-server.cpp b/source/slang/slang-language-server.cpp
index c188142f5..12151441c 100644
--- a/source/slang/slang-language-server.cpp
+++ b/source/slang/slang-language-server.cpp
@@ -458,7 +458,7 @@ void appendDefinitionLocation(StringBuilder& sb, Workspace* workspace, const Hum
sb << "Defined in " << pathSlice << "(" << loc.line << ")\n";
}
-HumaneSourceLoc getModuleLoc(SourceManager* manager, ModuleDecl* moduleDecl)
+HumaneSourceLoc getModuleLoc(SourceManager* manager, ContainerDecl* moduleDecl)
{
if (moduleDecl)
{
@@ -722,6 +722,27 @@ SlangResult LanguageServer::hover(
hover.range.end.character = (int)utf16Col;
}
}
+ else if (auto includeDeclBase = as<IncludeDeclBase>(leafNode))
+ {
+ 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);
+ Index 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);
+ hover.range.end.line = (int)utf16Line;
+ hover.range.end.character = (int)utf16Col;
+ }
+ }
else if (auto decl = as<Decl>(leafNode))
{
fillDeclRefHoverInfo(makeDeclRef(decl));
@@ -835,6 +856,14 @@ SlangResult LanguageServer::gotoDefinition(
locations.add(LocationResult{ location, 0 });
}
}
+ else if (auto includeDeclBase = as<IncludeDeclBase>(leafNode))
+ {
+ auto location = getModuleLoc(version->linkage->getSourceManager(), includeDeclBase->fileDecl);
+ if (location.pathInfo.hasFoundPath())
+ {
+ locations.add(LocationResult{ location, 0 });
+ }
+ }
if (locations.getCount() == 0)
{
m_connection->sendResult(NullResponse::get(), responseId);