From 1050e0eb96d6c8e7a6cfb253458155e1014625c3 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 5 Dec 2023 10:06:19 -0800 Subject: 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 --- source/slang/slang-language-server.cpp | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) (limited to 'source/slang/slang-language-server.cpp') 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(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(leafNode)) { fillDeclRefHoverInfo(makeDeclRef(decl)); @@ -835,6 +856,14 @@ SlangResult LanguageServer::gotoDefinition( locations.add(LocationResult{ location, 0 }); } } + else if (auto includeDeclBase = as(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); -- cgit v1.2.3