feat: reload LSP configuration
This commit is contained in:
parent
90c2848d63
commit
5e99a59f8d
39
src/lsp.rs
39
src/lsp.rs
|
|
@ -9,10 +9,11 @@ use tower_lsp_server::{
|
|||
ls_types::{
|
||||
CodeAction, CodeActionKind, CodeActionOptions, CodeActionOrCommand, CodeActionParams,
|
||||
CodeActionProviderCapability, CodeActionResponse, Diagnostic, DiagnosticSeverity,
|
||||
DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams,
|
||||
DocumentChanges, InitializeParams, InitializeResult, InitializedParams, NumberOrString,
|
||||
OneOf, OptionalVersionedTextDocumentIdentifier, Position, Range, ServerCapabilities,
|
||||
ServerInfo, TextDocumentEdit, TextDocumentSyncCapability, TextDocumentSyncKind,
|
||||
DidChangeConfigurationParams, DidChangeTextDocumentParams, DidCloseTextDocumentParams,
|
||||
DidOpenTextDocumentParams, DocumentChanges, InitializeParams, InitializeResult,
|
||||
InitializedParams, MessageType, NumberOrString, OneOf,
|
||||
OptionalVersionedTextDocumentIdentifier, Position, Range, ServerCapabilities, ServerInfo,
|
||||
TextDocumentEdit, TextDocumentSyncCapability, TextDocumentSyncKind,
|
||||
TextEdit as LspTextEdit, Uri, WorkspaceEdit,
|
||||
},
|
||||
};
|
||||
|
|
@ -254,13 +255,19 @@ impl DocumentStore {
|
|||
fn get(&self, uri: &Uri) -> Option<OpenDocument> {
|
||||
self.documents.get(uri).cloned()
|
||||
}
|
||||
|
||||
fn uris(&self) -> Vec<Uri> {
|
||||
let mut uris = self.documents.keys().cloned().collect::<Vec<_>>();
|
||||
uris.sort();
|
||||
uris
|
||||
}
|
||||
}
|
||||
|
||||
/// Stdio LSP backend backed by authoritative snapshots of open documents.
|
||||
#[derive(Debug)]
|
||||
pub struct LspBackend {
|
||||
client: Client,
|
||||
_config_loader: ConfigLoader,
|
||||
config_loader: ConfigLoader,
|
||||
config: RwLock<Config>,
|
||||
documents: RwLock<DocumentStore>,
|
||||
}
|
||||
|
|
@ -270,7 +277,7 @@ impl LspBackend {
|
|||
pub fn new(client: Client, config_loader: ConfigLoader, config: Config) -> Self {
|
||||
Self {
|
||||
client,
|
||||
_config_loader: config_loader,
|
||||
config_loader,
|
||||
config: RwLock::new(config),
|
||||
documents: RwLock::new(DocumentStore::default()),
|
||||
}
|
||||
|
|
@ -347,6 +354,26 @@ impl LanguageServer for LspBackend {
|
|||
self.client.publish_diagnostics(uri, Vec::new(), None).await;
|
||||
}
|
||||
|
||||
async fn did_change_configuration(&self, _: DidChangeConfigurationParams) {
|
||||
let config = match self.config_loader.load() {
|
||||
Ok(config) => config,
|
||||
Err(error) => {
|
||||
self.client
|
||||
.show_message(
|
||||
MessageType::ERROR,
|
||||
format!("John Slop configuration reload failed: {error}"),
|
||||
)
|
||||
.await;
|
||||
return;
|
||||
}
|
||||
};
|
||||
*self.config.write().await = config;
|
||||
let uris = self.documents.read().await.uris();
|
||||
for uri in uris {
|
||||
self.publish_replacements(uri).await;
|
||||
}
|
||||
}
|
||||
|
||||
async fn code_action(
|
||||
&self,
|
||||
params: CodeActionParams,
|
||||
|
|
|
|||
2
tasks.md
2
tasks.md
|
|
@ -199,7 +199,7 @@ first formatter milestone tag.
|
|||
initial release. Include stable codes and source `john-slop`.
|
||||
- [x] Expose quick fixes/code actions using the exact edits from the shared
|
||||
replacement engine; reject stale-version requests.
|
||||
- [ ] Recompute after open/change/configuration updates, clear on close, and avoid
|
||||
- [x] Recompute after open/change/configuration updates, clear on close, and avoid
|
||||
publishing obsolete results when analysis overlaps newer edits.
|
||||
- [ ] Keep all protocol bytes on stdout and diagnostics/logging on stderr. Add
|
||||
opt-in structured logging without document contents.
|
||||
|
|
|
|||
Loading…
Reference in New Issue