Skip to content

Commit 114737d

Browse files
committed
Fix findWorkspace function
Part of #88
1 parent e696cd5 commit 114737d

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
2222
- Fixed crash when hovering over local in incomplete syntax tree
2323
- Fixed language server not working for newly created files not yet stored on disk
2424
- Luau LSP will now activate if you run an LSP command
25+
- Fixed finding the incorrect workspace folder to analyze with in a multi-workspace environment
2526

2627
## [1.7.1] - 2022-07-17
2728

src/LanguageServer.cpp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,32 @@ using ClientPtr = std::shared_ptr<Client>;
2121
/// If no workspace is found, the file is attached to the null workspace
2222
WorkspaceFolderPtr LanguageServer::findWorkspace(const lsp::DocumentUri file)
2323
{
24+
WorkspaceFolderPtr bestWorkspace = nullptr;
25+
size_t length = 0;
26+
auto checkStr = file.toString();
27+
28+
2429
for (auto& workspace : workspaceFolders)
2530
{
26-
if (workspace->isInWorkspace(file))
31+
if (file == workspace->rootUri)
32+
return workspace;
33+
34+
// Check if the root uri is a prefix of the file
35+
auto prefixStr = workspace->rootUri.toString();
36+
auto size = prefixStr.size();
37+
if (size < length)
38+
continue;
39+
40+
if (checkStr.compare(0, size, prefixStr) == 0)
2741
{
28-
return workspace; // TODO: should we return early here? maybe a better match comes along?
42+
bestWorkspace = workspace;
43+
length = size;
2944
}
3045
}
46+
47+
if (bestWorkspace)
48+
return bestWorkspace;
49+
3150
client->sendTrace("cannot find workspace for " + file.toString());
3251
return nullWorkspace;
3352
}

0 commit comments

Comments
 (0)