-
Notifications
You must be signed in to change notification settings - Fork 122
Поддержка нескольких workspace в LSP #3662
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from 8 commits
cc6614a
1f91a40
53fc8ea
4494c04
1242dbb
346de9e
ee5dab8
cccfebf
0769e4f
6ffc8fa
f235d9d
9cf5e78
96cb67c
f494065
62f7494
7329dd0
c95e2c9
99c9239
355480f
755b111
5b404f7
3ac77e4
53c1255
e2134ae
e3c0ece
c088b4f
c72f8a2
abe3232
605467e
5d5860a
4908bb6
07c9067
3328552
5f460ab
3cb9100
a5a48e2
66e123f
6216a18
53ef16c
1ed4e37
4f57aa5
ca0e16f
5fddca5
a88d7f4
62fe105
3e94c47
cfe70e1
21f692d
70bc64b
d3001f5
79d9c35
99e8f92
112fa3c
b0d3da5
eb6bc4b
16fd9f9
8a4e5fb
0da1d8d
c7314fb
01fd681
cb6c919
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -23,6 +23,7 @@ | |
|
|
||
| import com.github._1c_syntax.bsl.languageserver.configuration.LanguageServerConfiguration; | ||
| import com.github._1c_syntax.bsl.languageserver.context.ServerContext; | ||
| import com.github._1c_syntax.bsl.languageserver.context.ServerContextProvider; | ||
| import com.github._1c_syntax.bsl.languageserver.jsonrpc.DiagnosticParams; | ||
| import com.github._1c_syntax.bsl.languageserver.jsonrpc.Diagnostics; | ||
| import com.github._1c_syntax.bsl.languageserver.jsonrpc.ProtocolExtension; | ||
|
|
@@ -62,6 +63,8 @@ | |
| import org.eclipse.lsp4j.TextDocumentClientCapabilities; | ||
| import org.eclipse.lsp4j.TextDocumentSyncKind; | ||
| import org.eclipse.lsp4j.TextDocumentSyncOptions; | ||
| import org.eclipse.lsp4j.WorkspaceFoldersOptions; | ||
| import org.eclipse.lsp4j.WorkspaceServerCapabilities; | ||
| import org.eclipse.lsp4j.WorkspaceSymbolOptions; | ||
| import org.eclipse.lsp4j.jsonrpc.messages.Either; | ||
| import org.eclipse.lsp4j.services.LanguageServer; | ||
|
|
@@ -97,7 +100,7 @@ public class BSLLanguageServer implements LanguageServer, ProtocolExtension { | |
| private final BSLWorkspaceService workspaceService; | ||
| private final CommandProvider commandProvider; | ||
| private final ClientCapabilitiesHolder clientCapabilitiesHolder; | ||
| private final ServerContext context; | ||
| private final ServerContextProvider serverContextProvider; | ||
| private final ServerInfo serverInfo; | ||
| private final SemanticTokensLegend legend; | ||
|
|
||
|
|
@@ -131,6 +134,7 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params) { | |
| capabilities.setExecuteCommandProvider(getExecuteCommandProvider()); | ||
| capabilities.setDiagnosticProvider(getDiagnosticProvider()); | ||
| capabilities.setSemanticTokensProvider(getSemanticTokensProvider()); | ||
| capabilities.setWorkspace(getWorkspaceCapabilities()); | ||
|
|
||
| var result = new InitializeResult(capabilities, serverInfo); | ||
|
|
||
|
|
@@ -143,31 +147,29 @@ private void setConfigurationRoot(InitializeParams params) { | |
| return; | ||
| } | ||
|
|
||
| var rootUri = workspaceFolders.get(0).getUri(); | ||
| Path rootPath; | ||
| try { | ||
| rootPath = new File(new URI(rootUri).getPath()).getCanonicalFile().toPath(); | ||
| } catch (URISyntaxException | IOException e) { | ||
| LOGGER.error("Can't read root URI from initialization params.", e); | ||
| return; | ||
| } | ||
|
|
||
| var configurationRoot = LanguageServerConfiguration.getCustomConfigurationRoot( | ||
| configuration, | ||
| rootPath); | ||
| context.setConfigurationRoot(configurationRoot); | ||
| // Добавляем все workspace folders | ||
| workspaceFolders.forEach(serverContextProvider::addWorkspace); | ||
| } | ||
|
|
||
| @Override | ||
| public void initialized(InitializedParams params) { | ||
| var factory = new NamedForkJoinWorkerThreadFactory("populate-context-"); | ||
|
||
| var executorService = new ForkJoinPool(ForkJoinPool.getCommonPoolParallelism(), factory, null, true); | ||
| CompletableFuture | ||
| .runAsync(context::populateContext, executorService) | ||
|
|
||
| // Populate all workspace contexts | ||
| var allContexts = serverContextProvider.getAllContexts(); | ||
| var tasks = allContexts.stream() | ||
| .map(serverContext -> CompletableFuture.runAsync( | ||
| serverContext::populateContext, | ||
| executorService | ||
| )) | ||
| .toArray(CompletableFuture[]::new); | ||
|
|
||
| CompletableFuture.allOf(tasks) | ||
| .whenComplete((Void unused, @Nullable Throwable throwable) -> { | ||
| executorService.shutdown(); | ||
| if (throwable != null) { | ||
| LOGGER.error("Error populating context", throwable); | ||
| LOGGER.error("Error populating workspace contexts", throwable); | ||
| } | ||
| }); | ||
| } | ||
|
|
@@ -176,7 +178,7 @@ public void initialized(InitializedParams params) { | |
| public CompletableFuture<Object> shutdown() { | ||
| shutdownWasCalled = true; | ||
| textDocumentService.reset(); | ||
| context.clear(); | ||
| serverContextProvider.clear(); | ||
| return CompletableFuture.completedFuture(Boolean.TRUE); | ||
| } | ||
|
|
||
|
|
@@ -384,4 +386,15 @@ private SemanticTokensWithRegistrationOptions getSemanticTokensProvider() { | |
| return semanticTokensProvider; | ||
| } | ||
|
|
||
| private static WorkspaceServerCapabilities getWorkspaceCapabilities() { | ||
| var workspaceCapabilities = new WorkspaceServerCapabilities(); | ||
|
|
||
| var workspaceFoldersOptions = new WorkspaceFoldersOptions(); | ||
| workspaceFoldersOptions.setSupported(Boolean.TRUE); | ||
| workspaceFoldersOptions.setChangeNotifications(Boolean.TRUE); | ||
|
|
||
| workspaceCapabilities.setWorkspaceFolders(workspaceFoldersOptions); | ||
| return workspaceCapabilities; | ||
| } | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.