diff options
| author | Yong He <yonghe@outlook.com> | 2023-12-05 10:06:19 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-05 10:06:19 -0800 |
| commit | 1050e0eb96d6c8e7a6cfb253458155e1014625c3 (patch) | |
| tree | ce6c3cbde591759fa2fe2aeb05cb132e50a9a419 /source/slang/slang-language-server-completion.cpp | |
| parent | 4fb3b10b81cf8c976ebd1ebb7fcde7708f022957 (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-completion.cpp')
| -rw-r--r-- | source/slang/slang-language-server-completion.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/source/slang/slang-language-server-completion.cpp b/source/slang/slang-language-server-completion.cpp index 58ee766cc..7b01dac34 100644 --- a/source/slang/slang-language-server-completion.cpp +++ b/source/slang/slang-language-server-completion.cpp @@ -293,16 +293,24 @@ List<LanguageServerProtocol::TextEditCompletionItem> CompletionContext::gatherFi SlangResult CompletionContext::tryCompleteImport() { - static auto importStr = UnownedStringSlice("import "); - auto lineContent = doc->getLine(line); - Index pos = lineContent.indexOf(importStr); - if (pos == -1) - return SLANG_FAIL; - auto lineBeforeImportKeyword = lineContent.head(pos).trim(); - if (lineBeforeImportKeyword.getLength() != 0 && lineBeforeImportKeyword != "__exported") - return SLANG_FAIL; - - pos += importStr.getLength(); + const char* prefixes[] = { "import ", "__include ", "implementing " }; + UnownedStringSlice lineContent; + Index pos = -1; + for (auto prefix : prefixes) + { + static auto importStr = UnownedStringSlice(prefix); + lineContent = doc->getLine(line); + pos = lineContent.indexOf(importStr); + if (pos == -1) + continue; + auto lineBeforeImportKeyword = lineContent.head(pos).trim(); + if (lineBeforeImportKeyword.getLength() != 0 && lineBeforeImportKeyword != "__exported") + continue; + pos += importStr.getLength(); + goto validLine; + } + return SLANG_FAIL; +validLine:; while (pos < lineContent.getLength() && pos < col - 1 && CharUtil::isWhitespace(lineContent[pos])) pos++; if (pos < lineContent.getLength() && lineContent[pos] == '"') |
