Skip to content

Commit

Permalink
feat: Support listen for server status changes
Browse files Browse the repository at this point in the history
Fixes #807

Signed-off-by: azerr <[email protected]>
  • Loading branch information
angelozerr committed Feb 7, 2025
1 parent bfbd17d commit e841a75
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/LSPApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class MyLanguageServerFactory implements LanguageServerFactory {
|--------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-------------------|
| boolean isEnabled(VirtualFile) | Returns `true` if the language server is enabled for the given file and `false` otherwise. | `true` |
| void initializeParams(InitializeParams) | This method is invoked just before [LanguageServer#initialize(InitializeParams)](https://github.com/eclipse-lsp4j/lsp4j/blob/651eb49e1f4cd90439808885ddaad0862b330908/org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/services/LanguageServer.java#L50) <br/>to enable customization of the language server's initialization parameters (e.g., {@link InitializeParams#getWorkDoneToken()}). | |
| void handleServerStatusChanged(ServerStatus) | Callback invoked when language server status changed. | |
| URI getFileUri(VirtualFile file) | Returns the file Uri from the given virtual file and null otherwise (to use default `FileUriSupport.DEFAULT.getFileUri`). | `null` |
| VirtualFile findFileByUri(String fileUri) | Returns the virtual file found by the given file Uri and null otherwise (to use default `FileUriSupport.DEFAULT.findFileByUri`). | `null` |
| boolean isCaseSensitive(PsiFile file) | Returns `true` if the language grammar for the given file is case-sensitive and `false` otherwise. | `false` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ private void updateStatus(ServerStatus serverStatus) {
if (languageClient != null) {
languageClient.handleServerStatusChanged(serverStatus);
}
getClientFeatures().handleServerStatusChanged(serverStatus);
}

private void startStopTimer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,19 @@ protected void triggerChangeConfiguration() {
* </ul>
*
* <p>
* If you need to track all status, you can do that by implementing {@link LSPClientFeatures#handleServerStatusChanged(ServerStatus)}.
* </p>
*
* <p>
* This method could be implemented to send 'workspace/didChangeConfiguration' (by calling triggerChangeConfiguration)
* when server is started.
* The implementation must be fast or execute asynchronously to avoid deteriorate startup of language server performance.
* </p>
*
* @param serverStatus server status
*/
public void handleServerStatusChanged(ServerStatus serverStatus) {

public void handleServerStatusChanged(@NotNull ServerStatus serverStatus) {
// Do nothing
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ public boolean isEnabled(@NotNull VirtualFile file) {
return true;
}

/**
* Callback invoked when language server status changed.
*
* @param serverStatus server status
*/
public void handleServerStatusChanged(@NotNull ServerStatus serverStatus) {
// Do nothing
}

/**
* This method is invoked just before {@link LanguageServer#initialize(InitializeParams)}
* to enable customization of the language server's initialization parameters
Expand Down

0 comments on commit e841a75

Please sign in to comment.