summaryrefslogtreecommitdiff
path: root/source/slang/slang-workspace-version.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-06-13 16:50:35 -0700
committerGitHub <noreply@github.com>2022-06-13 16:50:35 -0700
commita5422d4f8c43962147696e3b6b22d586133b9a4f (patch)
treeac7541219ec1ea789c8a470471c8b37fbc4ac29e /source/slang/slang-workspace-version.cpp
parentb0c7eb885dac6b609a46a961feb71d2f983a0d76 (diff)
Follow up on Language Server Improvement (#2275)
* Fix typo and improve parser recovery. * Add search path configuration. Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-workspace-version.cpp')
-rw-r--r--source/slang/slang-workspace-version.cpp60
1 files changed, 55 insertions, 5 deletions
diff --git a/source/slang/slang-workspace-version.cpp b/source/slang/slang-workspace-version.cpp
index d93be86b7..2742c083c 100644
--- a/source/slang/slang-workspace-version.cpp
+++ b/source/slang/slang-workspace-version.cpp
@@ -32,7 +32,7 @@ DocumentVersion* Workspace::openDoc(String path, String text)
doc->setText(text.getUnownedSlice());
doc->setURI(URI::fromLocalFilePath(path.getUnownedSlice()));
openedDocuments[path] = doc;
- searchPaths.Add(Path::getParentDirectory(path));
+ workspaceSearchPaths.Add(Path::getParentDirectory(path));
moduleCache.invalidate(path);
invalidate();
return doc.Ptr();
@@ -66,11 +66,11 @@ void Workspace::closeDoc(const String& path)
bool Workspace::updatePredefinedMacros(List<String> macros)
{
- List<OnwedPreprocessorMacroDefinition> newDefs;
+ List<OwnedPreprocessorMacroDefinition> newDefs;
for (auto macro : macros)
{
auto index = macro.indexOf('=');
- OnwedPreprocessorMacroDefinition def;
+ OwnedPreprocessorMacroDefinition def;
def.name = macro.getUnownedSlice().head(index).trim();
if (index != -1)
{
@@ -102,6 +102,41 @@ bool Workspace::updatePredefinedMacros(List<String> macros)
return changed;
}
+bool Workspace::updateSearchPaths(List<String> paths)
+{
+ bool changed = false;
+ if (paths.getCount() != additionalSearchPaths.getCount())
+ changed = true;
+ else
+ {
+ for (Index i = 0; i < paths.getCount(); i++)
+ {
+ if (paths[i] != additionalSearchPaths[i])
+ {
+ changed = true;
+ break;
+ }
+ }
+ }
+ if (changed)
+ {
+ additionalSearchPaths = _Move(paths);
+ invalidate();
+ }
+ return changed;
+}
+
+bool Workspace::updateSearchInWorkspace(bool value)
+{
+ bool changed = searchInWorkspace != value;
+ searchInWorkspace = value;
+ if (changed)
+ {
+ invalidate();
+ }
+ return changed;
+}
+
void Workspace::init(List<URI> rootDirURI, slang::IGlobalSession* globalSession)
{
for (auto uri : rootDirURI)
@@ -132,7 +167,7 @@ void Workspace::init(List<URI> rootDirURI, slang::IGlobalSession* globalSession)
},
&context);
}
- searchPaths = _Move(context.paths);
+ workspaceSearchPaths = _Move(context.paths);
}
slangGlobalSession = globalSession;
}
@@ -239,8 +274,23 @@ RefPtr<WorkspaceVersion> Workspace::createWorkspaceVersion()
targetDesc.profile = slangGlobalSession->findProfile("sm_6_6");
desc.targets = &targetDesc;
List<const char*> searchPathsRaw;
- for (auto path : searchPaths)
+ for (auto& path : additionalSearchPaths)
searchPathsRaw.add(path.getBuffer());
+ if (searchInWorkspace)
+ {
+ for (auto& path : workspaceSearchPaths)
+ searchPathsRaw.add(path.getBuffer());
+ }
+ else
+ {
+ HashSet<String> set;
+ for (auto& p : openedDocuments)
+ {
+ auto dir = Path::getParentDirectory(p.Key.getBuffer());
+ if (set.Add(dir))
+ searchPathsRaw.add(dir.getBuffer());
+ }
+ }
desc.searchPaths = searchPathsRaw.getBuffer();
desc.searchPathCount = searchPathsRaw.getCount();