-
Notifications
You must be signed in to change notification settings - Fork 116
Add support for textDocument/diagnostic and workspace/diagnostic/refresh (LSP 3.17) #3557
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 all commits
8847f41
2650755
8bce6b2
712373b
9ae7be9
5d80665
63c03f2
a236b9e
8c5606b
e5cbb95
5352e03
a48c1c8
5506fd3
3bfdeab
ea9dc69
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 |
|---|---|---|
|
|
@@ -21,31 +21,49 @@ | |
| */ | ||
| package com.github._1c_syntax.bsl.languageserver.providers; | ||
|
|
||
| import com.github._1c_syntax.bsl.languageserver.ClientCapabilitiesHolder; | ||
| import com.github._1c_syntax.bsl.languageserver.LanguageClientHolder; | ||
| import com.github._1c_syntax.bsl.languageserver.configuration.events.LanguageServerConfigurationChangedEvent; | ||
| import com.github._1c_syntax.bsl.languageserver.context.DocumentContext; | ||
| import com.github._1c_syntax.bsl.languageserver.events.LanguageServerInitializeRequestReceivedEvent; | ||
| import lombok.RequiredArgsConstructor; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.eclipse.lsp4j.ClientCapabilities; | ||
| import org.eclipse.lsp4j.Diagnostic; | ||
| import org.eclipse.lsp4j.DiagnosticWorkspaceCapabilities; | ||
| import org.eclipse.lsp4j.DocumentDiagnosticReport; | ||
| import org.eclipse.lsp4j.PublishDiagnosticsParams; | ||
| import org.eclipse.lsp4j.RelatedFullDocumentDiagnosticReport; | ||
| import org.eclipse.lsp4j.WorkspaceClientCapabilities; | ||
| import org.springframework.context.event.EventListener; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.function.Supplier; | ||
|
|
||
| /** | ||
| * Провайдер для публикации диагностических сообщений. | ||
| * Провайдер для диагностических сообщений. | ||
| * <p> | ||
| * Отвечает за публикацию диагностик с использованием {@code textDocument/publishDiagnostics}. | ||
| * Отвечает за публикацию диагностик с использованием {@code textDocument/publishDiagnostics}, | ||
| * предоставление диагностик по запросу {@code textDocument/diagnostic} | ||
| * и уведомление об обновлении диагностик через {@code workspace/diagnostic/refresh}. | ||
| * | ||
| * @see <a href="https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_publishDiagnostics">PublishDiagnostics Notification specification</a> | ||
| * @see <a href="https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#textDocument_diagnostic">Diagnostic Pull Request specification</a> | ||
| * @see <a href="https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#diagnostic_refresh">Diagnostic Refresh Request specification</a> | ||
| */ | ||
| @Slf4j | ||
| @Component | ||
| @RequiredArgsConstructor | ||
| public final class DiagnosticProvider { | ||
|
|
||
| public static final String SOURCE = "bsl-language-server"; | ||
|
|
||
| private final LanguageClientHolder clientHolder; | ||
| private final ClientCapabilitiesHolder clientCapabilitiesHolder; | ||
|
|
||
| private boolean clientSupportsRefresh; | ||
|
|
||
| /** | ||
| * Вычислить и опубликовать диагностики для документа. | ||
|
|
@@ -56,6 +74,18 @@ public void computeAndPublishDiagnostics(DocumentContext documentContext) { | |
| publishDiagnostics(documentContext, documentContext::getDiagnostics); | ||
| } | ||
|
|
||
| /** | ||
| * Получить диагностики для документа (pull-модель). | ||
| * | ||
| * @param documentContext Контекст документа | ||
| * @return Отчет с диагностиками | ||
| */ | ||
| public DocumentDiagnosticReport getDiagnostic(DocumentContext documentContext) { | ||
nixel2007 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| var diagnostics = documentContext.getDiagnostics(); | ||
| var report = new RelatedFullDocumentDiagnosticReport(diagnostics); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @copilot давай попробуем сделать поддержку unchanged report. Где-то нужно хранить reportID и список диагностик с прошлого запуска. Предложи архитектуру решения, но НЕ РЕАЛИЗОВЫВАЙ. только схемы и описание. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Architecture proposal for unchanged report supportComponents needed:
Challenges:
|
||
| return new DocumentDiagnosticReport(report); | ||
| } | ||
|
|
||
| /** | ||
| * Опубликовать пустой список диагностик для документа. | ||
| * | ||
|
|
@@ -65,6 +95,39 @@ public void publishEmptyDiagnosticList(DocumentContext documentContext) { | |
| publishDiagnostics(documentContext, Collections::emptyList); | ||
| } | ||
|
|
||
| /** | ||
| * Обработчик события {@link LanguageServerInitializeRequestReceivedEvent}. | ||
| * <p> | ||
| * Проверяет поддержку клиентом workspace/diagnostic/refresh. | ||
| * | ||
| * @param event Событие | ||
| */ | ||
| @EventListener | ||
| public void handleInitializeEvent(LanguageServerInitializeRequestReceivedEvent event) { | ||
| clientSupportsRefresh = clientCapabilitiesHolder.getCapabilities() | ||
| .map(ClientCapabilities::getWorkspace) | ||
| .map(WorkspaceClientCapabilities::getDiagnostics) | ||
| .map(DiagnosticWorkspaceCapabilities::getRefreshSupport) | ||
| .orElse(false); | ||
| } | ||
|
|
||
| /** | ||
| * Обработчик события {@link LanguageServerConfigurationChangedEvent}. | ||
| * <p> | ||
| * Отправляет клиенту запрос на обновление диагностик при изменении конфигурации. | ||
| * | ||
| * @param event Событие | ||
| */ | ||
| @EventListener | ||
| public void handleConfigurationChangedEvent(LanguageServerConfigurationChangedEvent event) { | ||
| if (clientSupportsRefresh) { | ||
| clientHolder.execIfConnected(languageClient -> { | ||
| LOGGER.debug("Requesting diagnostic refresh from client"); | ||
| languageClient.refreshDiagnostics(); | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| private void publishDiagnostics(DocumentContext documentContext, Supplier<List<Diagnostic>> diagnostics) { | ||
| clientHolder.execIfConnected(languageClient -> | ||
| languageClient.publishDiagnostics( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot насколько сложно сделать поддержку workDoneProgress? Предложи вариант решения, но НЕ РЕАЛИЗОВЫВАЙ.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Architecture proposal for workDoneProgress support
Complexity: Medium
Components needed:
WorkDoneProgressHelper integration:
DiagnosticProvider changes:
Implementation approach:
Challenges: