Skip to content

Commit e559d65

Browse files
committed
Fix multi workspaceFolder
1 parent f89e879 commit e559d65

File tree

1 file changed

+28
-8
lines changed

1 file changed

+28
-8
lines changed

EmmyLua.LanguageServer/Server/ServerContext.cs

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class ServerContext(Framework.Server.LanguageServer server)
3838
public ResourceManager ResourceManager { get; } = new();
3939

4040
private CancellationTokenSource? WorkspaceCancellationTokenSource { get; set; } = null;
41-
41+
4242
private EditorconfigWatcher EditorconfigWatcher { get; } = new();
4343

4444
public async Task StartServerAsync(InitializeParams initializeParams)
@@ -85,24 +85,45 @@ private void StartServer(InitializeParams initializeParams)
8585
LockSlim.EnterWriteLock();
8686
try
8787
{
88-
var rootPath = string.Empty;
8988
if (initializeParams.RootUri is { } rootUri)
9089
{
91-
rootPath = rootUri.FileSystemPath;
90+
var rootPath = rootUri.FileSystemPath;
91+
MainWorkspacePath = rootPath;
9292
}
9393

94-
if (rootPath.Length > 0)
94+
SettingManager.SupportMultiEncoding();
95+
if (MainWorkspacePath.Length == 0)
96+
{
97+
if (initializeParams.WorkspaceFolders is { } workspaceFolders)
98+
{
99+
foreach (var workspaceFolder in workspaceFolders)
100+
{
101+
var path = workspaceFolder.Uri.FileSystemPath;
102+
var emmyrcPath = Path.Combine(path, SettingManager.ConfigName);
103+
if (File.Exists(emmyrcPath))
104+
{
105+
MainWorkspacePath = path;
106+
break;
107+
}
108+
}
109+
110+
if (MainWorkspacePath.Length == 0 && workspaceFolders.Count > 0)
111+
{
112+
MainWorkspacePath = workspaceFolders[0].Uri.FileSystemPath;
113+
}
114+
}
115+
}
116+
117+
if (MainWorkspacePath.Length > 0)
95118
{
96-
MainWorkspacePath = rootPath;
97119
LuaProject.Monitor = Monitor;
98-
SettingManager.SupportMultiEncoding();
99120
SettingManager.Watch(MainWorkspacePath);
100121
SettingManager.OnSettingChanged += OnConfigChanged;
101122
SettingManager.WorkspaceExtensions = Extensions;
102123
LuaProject.MainWorkspacePath = MainWorkspacePath;
103124
LuaProject.Features = SettingManager.GetLuaFeatures();
104125
LuaProject.InitStdLib();
105-
if (IsVscode && initializeParams.WorkspaceFolders is { } workspaceFolders)
126+
if (initializeParams.WorkspaceFolders is { } workspaceFolders)
106127
{
107128
foreach (var workspaceFolder in workspaceFolders)
108129
{
@@ -115,7 +136,6 @@ private void StartServer(InitializeParams initializeParams)
115136
}
116137
}
117138
}
118-
// TODO: read config from initializeOptions
119139

120140
LuaProject.LoadMainWorkspace(MainWorkspacePath);
121141
EditorconfigWatcher.LoadWorkspaceEditorconfig(MainWorkspacePath);

0 commit comments

Comments
 (0)