Skip to content

Fix workspace removal events not published during ServerContextProvider.clear()#3662

Open
Copilot wants to merge 92 commits intodevelopfrom
copilot/support-multiple-workspaces
Open

Fix workspace removal events not published during ServerContextProvider.clear()#3662
Copilot wants to merge 92 commits intodevelopfrom
copilot/support-multiple-workspaces

Conversation

Copy link
Contributor

Copilot AI commented Dec 14, 2025

Problem

ConfigurationFileSystemWatcher maintained stale workspace URIs in its workspaceWatchKeys map after ServerContextProvider.clear() was called. This caused IllegalStateException when the watcher tried to use removed workspaces.

Root cause: clear() directly removed workspaces without publishing BeforeWorkspaceRemovedEvent, preventing event listeners from cleaning up their state.

Changes

  • Added AOP pointcut for ServerContextProvider.clear() in Pointcuts
  • Added @Before advice in EventPublisherAspect to publish BeforeWorkspaceRemovedEvent for each workspace before clearing
  • Ensures event-driven cleanup (like ConfigurationFileSystemWatcher unregistering watch keys) works correctly during bulk workspace removal

The fix maintains consistency with the existing event-driven architecture where workspace removal always triggers cleanup events, whether workspaces are removed individually or in bulk.

Original prompt

Поддержка нескольких workspace в lsp.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 14, 2025

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

  • 🔍 Trigger a full review

Comment @coderabbitai help to get the list of available commands and usage tips.

Copilot AI and others added 5 commits December 14, 2025 09:37
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
…xtProvider

Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for multiple workspaces in LSP Поддержка нескольких workspace в LSP Dec 14, 2025
Copilot AI requested a review from nixel2007 December 14, 2025 10:17
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
Co-authored-by: nixel2007 <1132840+nixel2007@users.noreply.github.com>
nixel2007 and others added 9 commits February 27, 2026 13:01
…wired

Migrate main and test consumers of ServerContext.getLanguageServerConfiguration()
to use @Autowired workspace-scoped LanguageServerConfiguration proxy:

Main files:
- DiagnosticsConfiguration: use @Autowired LSC field
- SarifReporter: add LSC constructor parameter
- AnalyzeProjectOnStart: add @Autowired LSC, set ThreadLocal from event
- AnalyzeCommand: add @Autowired LSC, wrap in try/finally with ThreadLocal
- ConfigurationFileSystemWatcher: store LSC directly instead of ServerContext
- ConfigurationFileChangeListener: accept LSC instead of ServerContext

Test files (18): migrate from serverContext navigation to @Autowired LSC

The getter on ServerContext is kept for DocumentContext (not a Spring bean).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Add AutoCloseable forUri() and wrap methods run()/call() to eliminate
manual set/clear boilerplate. forUri() supports nesting by saving and
restoring the previous ThreadLocal value on close.

Migrate all existing set/clear call sites:
- BSLLanguageServer.initialized: forUri (try-with-resources)
- BSLWorkspaceService.didChangeWorkspaceFolders: run()
- ServerContextProvider.addWorkspace: forUri (try-with-resources)
- AnalyzeProjectOnStart.handleEvent: forUri (try-with-resources)
- AnalyzeCommand.execute: forUri (try-with-resources)

Add comprehensive unit tests for all new methods including
nesting, restore, and exception safety.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore original field ordering, blank lines between @Autowired fields,
and remove unnecessary method signature / call site line breaks introduced
during multi-pass refactoring:

- QuickFixSupplier, QuickFixCodeActionSupplier, FixAllCodeActionSupplier:
  put method signatures and calls back on single lines
- ConstructorColorPresentationSupplier, WebColorPresentationSupplier:
  restore static constants before instance fields
- AbstractMethodComplexityCodeLensSupplier: restore field order and javadoc
- CognitiveComplexity/CyclomaticComplexityCodeLensSupplier: match parent field order
- DisableDiagnosticTriggeringSupplier: restore static constant position
- CommonModuleInvalidTypeDiagnostic: remove extra blank line
- 15 test files: restore field ordering and blank lines

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix @OverRide indentation lost in 5 diagnostic files
- Remove duplicate CF import in ServerContext
- Restore field ordering to match develop in 4 files
- Fix trailing whitespace in 22 files

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Restore protected visibility for configuration field
- Remove @Getter(AccessLevel.PROTECTED) in AbstractRunTestsCodeLensSupplier
- Remove unused documentContext param from getComplexityThreshold()
- Keep only meaningful change: configuration param in @Cacheable getTestSources()

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…nModuleNameDiagnostic

Restore constructor parameter for LanguageServerConfiguration in the abstract
class and all 9 subclasses. Spring injects the workspace-scoped proxy via
constructor just as well, @Autowired field injection is unnecessary.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore the standard Spring BeanPostProcessor pattern for diagnostic
initialization instead of the custom initAfterInfoSet() approach.

- Recreate DiagnosticBeanPostProcessor with @lazy constructor to avoid
  early initialization warnings for workspace-scoped dependencies
- Restore @PostConstruct in 5 diagnostics that need info for init
- Remove initAfterInfoSet() from BSLDiagnostic interface
- Revert DiagnosticObjectProvider to simple get(Class) method
- Revert callers in DiagnosticsConfiguration and QuickFixSupplier

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Restore original getResourceString(key) private method pattern in
DescriptionFormatter, ModuleSymbolMarkupContentBuilder, and
VariableSymbolMarkupContentBuilder. The resources field is already
available — no need to pass it as a parameter.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ltiple-workspaces

# Conflicts:
#	src/main/java/com/github/_1c_syntax/bsl/languageserver/BSLLanguageServer.java
#	src/test/java/com/github/_1c_syntax/bsl/languageserver/diagnostics/infrastructure/MinimumLSPDiagnosticLevelTest.java
#	src/test/java/com/github/_1c_syntax/bsl/languageserver/inlayhints/SourceDefinedMethodCallInlayHintSupplierTest.java
#	src/test/java/com/github/_1c_syntax/bsl/languageserver/providers/SemanticTokensProviderTest.java
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 136 out of 138 changed files in this pull request and generated no new comments.

nixel2007 and others added 16 commits February 27, 2026 18:39
Resolve language from workspace-scoped LanguageServerConfiguration
when workspace context is set, otherwise fall back to
GlobalLanguageServerConfiguration.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Make context a private field in AnalyzeCommand (like FormatCommand),
rename to serverContext for consistency, remove context parameter
from getFileInfoFromFile.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Wrap formatting work in WorkspaceContextHolder.forUri() so that
workspace-scoped proxies resolve correctly, consistent with
AnalyzeCommand pattern.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…Local propagation

- WorkspaceScope.resolveKey() throws IllegalStateException instead of falling back
- Remove DEFAULT_WORKSPACE_KEY constant
- Add WorkspaceContextTestExecutionListener for test ThreadLocal setup
- Fix parallelStream ThreadLocal propagation (always set, not just when null)
- Fix circular bean creation in LanguageServerConfiguration @PostConstruct
- Add null guard in AnalyzeProjectOnStart for workspaceUri
- Fix ConfigurationFileSystemWatcher to set workspace context
- Fix ServerContextProvider.clear() to also clean workspace scope beans
- Fix ConfigurationFileSystemWatcherTest for awaitility thread context

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…g parameter passing

- MissingCommonModuleMethodDiagnostic: revert to @requiredargsconstructor + private final
- OrdinaryAppSupportDiagnostic: revert to @requiredargsconstructor + private final
- FormatProvider: remove explicit LanguageServerConfiguration parameter passing through
  method chain — use the injected per-workspace proxy field directly
- IdenticalExpressionsDiagnostic: remove unnecessary LSC injection (FormatProvider handles it)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…xecutors

- ServerContext: inject populateContextExecutor, wrap parallelStream
- AnalyzeCommand/FormatCommand: inject cliExecutor, wrap parallelStream
- Remove manual WorkspaceContextHolder propagation helpers
- DiagnosticInfo: cache language and codeDescriptionHref to avoid
  workspace proxy access from common ForkJoinPool worker threads
- Add cliExecutor bean in ExecutorConfiguration
- Fix DocumentLink test to refresh DiagnosticInfos after config changes

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
On Windows, Absolute.uri() normalizes file:///test-analyze-workspace to
include a drive letter (e.g. file:///C:/test-analyze-workspace). Using the
raw URI for WorkspaceContextHolder.set() caused a key mismatch with
workspace-scoped bean registry, making AnalyzeProjectOnStartTest fail on
Windows.

Use context.getWorkspaceUri().toString() (already normalized by
addWorkspace) instead of raw URIs.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
WorkspaceContextHolder now accepts and stores java.net.URI, normalizing
via Absolute.uri() on set. This eliminates the class of bugs where raw
URI strings didn't match normalized ones (e.g. Windows adding drive
letter to file:///test-workspace → file:///C:/test-workspace).

WorkspaceScope internal maps also changed from String to URI keys.
All callers updated to pass URI directly instead of uri.toString().

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Avoids serial lock-file retry delays on Windows (~25s → ~2.5s).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Callers must pass already-normalized URIs. Test constants
use Absolute.uri() to normalize, fixing Windows CI failures.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…tate

Reverted: GenerateStandardRegionsSupplier field rename,
AbstractRunTestsCodeLensSupplier configuration parameter,
CodeLensesConfiguration filtering moved back here.
CodeLensProvider uses lazy ObjectProvider evaluation.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Remove Absolute.uri() from addWorkspace(URI, String) — callers must
  pass already-normalized URIs
- Change AOP args(workspaceUri) to args(workspaceUri, *) to match the
  two-parameter addWorkspace(URI, String) overload directly
- Normalize URI in ConfigurationFileSystemWatcherTest setUp

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…AllContexts

- AnalyzeProjectOnStart: remove redundant WorkspaceContextHolder.forUri() wrapper
  (context propagated via ContextPropagatingTaskDecorator for @async)
- BSLLanguageServer: use Map.Entry key instead of serverContext.getWorkspaceUri()
- BSLWorkspaceService: extract URI from folder directly
- ServerContextProvider.getAllContexts(): return Map<URI, ServerContext>
- SymbolProvider, TestUtils: adapt to new return type

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ility

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 2, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarQube Cloud

- Add registerWorkspace/unregisterWorkspace to WorkspaceContextHolder
- forUri(URI) resolves name from registry, throws if not registered
- Move extractWorkspaceName to ServerContextProvider
- ServerContextProvider registers/unregisters names on add/remove/clear
- Clean up tests to use registration API

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nixel2007
Copy link
Member

@copilot падает один тест, поправь.

Copy link
Contributor Author

Copilot AI commented Mar 2, 2026

@copilot падает один тест, поправь.

Какой именно тест падает? Полный запуск тестов занимает очень много времени. Если укажете название теста, я смогу быстрее его исправить с помощью ./gradlew test --tests "ИмяТеста".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants