From 68b23147695c6a76e4aaf503b97edc4c5593b6e5 Mon Sep 17 00:00:00 2001 From: Matthew Espino <65783406+mcecode@users.noreply.github.com> Date: Sat, 26 Oct 2024 03:30:46 +0800 Subject: [PATCH] build-debug --- .github/workflows/build-debug-harper-ls.yml | 28 +++++++++ harper-ls/src/backend.rs | 66 +++++++++++++++++++-- 2 files changed, 89 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/build-debug-harper-ls.yml diff --git a/.github/workflows/build-debug-harper-ls.yml b/.github/workflows/build-debug-harper-ls.yml new file mode 100644 index 00000000..e0362782 --- /dev/null +++ b/.github/workflows/build-debug-harper-ls.yml @@ -0,0 +1,28 @@ +name: Build Debug + +on: + push: + branches: ["build-debug-harper-ls"] + +jobs: + build: + name: Build + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@v4 + - uses: dtolnay/rust-toolchain@master + with: + toolchain: stable + targets: x86_64-unknown-linux-gnu + - name: Build + run: cargo +stable build --locked --profile dev --bin harper-ls --target x86_64-unknown-linux-gnu + - name: Archive + run: | + cd target/x86_64-unknown-linux-gnu/debug + tar -czf ../../../harper-ls.tar.gz harper-ls + cd - + - name: Upload + uses: actions/upload-artifact@v4 + with: + name: debug-build + path: harper-ls.tar.gz diff --git a/harper-ls/src/backend.rs b/harper-ls/src/backend.rs index 73ceedeb..b5afe595 100644 --- a/harper-ls/src/backend.rs +++ b/harper-ls/src/backend.rs @@ -17,12 +17,14 @@ use tower_lsp::jsonrpc::Result; use tower_lsp::lsp_types::notification::PublishDiagnostics; use tower_lsp::lsp_types::{ CodeActionOrCommand, CodeActionParams, CodeActionProviderCapability, CodeActionResponse, - Command, ConfigurationItem, Diagnostic, DidChangeConfigurationParams, + Command, ConfigurationItem, DeleteFilesParams, Diagnostic, DidChangeConfigurationParams, DidChangeTextDocumentParams, DidCloseTextDocumentParams, DidOpenTextDocumentParams, - DidSaveTextDocumentParams, ExecuteCommandOptions, ExecuteCommandParams, InitializeParams, - InitializeResult, InitializedParams, MessageType, PublishDiagnosticsParams, Range, - ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind, TextDocumentSyncOptions, - TextDocumentSyncSaveOptions, Url, + DidSaveTextDocumentParams, ExecuteCommandOptions, ExecuteCommandParams, FileOperationFilter, + FileOperationPattern, FileOperationPatternKind, FileOperationRegistrationOptions, + InitializeParams, InitializeResult, InitializedParams, MessageType, PublishDiagnosticsParams, + Range, ServerCapabilities, TextDocumentSyncCapability, TextDocumentSyncKind, + TextDocumentSyncOptions, TextDocumentSyncSaveOptions, Url, + WorkspaceFileOperationsServerCapabilities, WorkspaceServerCapabilities, }; use tower_lsp::{Client, LanguageServer}; use tracing::{error, info}; @@ -361,6 +363,32 @@ impl LanguageServer for Backend { save: Some(TextDocumentSyncSaveOptions::Supported(true)), }, )), + workspace: Some(WorkspaceServerCapabilities { + workspace_folders: None, + file_operations: Some(WorkspaceFileOperationsServerCapabilities { + did_delete: Some(FileOperationRegistrationOptions { + filters: vec![ + FileOperationFilter { + scheme: Some("file".to_owned()), + pattern: FileOperationPattern { + glob: "**/*".to_owned(), + matches: Some(FileOperationPatternKind::File), + options: None, + }, + }, + FileOperationFilter { + scheme: Some("file".to_owned()), + pattern: FileOperationPattern { + glob: "**/*".to_owned(), + matches: Some(FileOperationPatternKind::Folder), + options: None, + }, + }, + ], + }), + ..Default::default() + }), + }), ..Default::default() }, }) @@ -407,6 +435,34 @@ impl LanguageServer for Backend { async fn did_close(&self, _params: DidCloseTextDocumentParams) {} + async fn did_delete_files(&self, params: DeleteFilesParams) { + let mut doc_lock = self.doc_state.lock().await; + let mut urls_to_clear = Vec::new(); + + for file in params.files { + doc_lock.retain(|url, _| { + // `file.uri` could be a directory so use `starts_with` rather than `==` + let to_remove = url.to_string().starts_with(&file.uri); + + if to_remove { + urls_to_clear.push(url.clone()); + } + + !to_remove + }); + } + + for url in &urls_to_clear { + self.client + .send_notification::(PublishDiagnosticsParams { + uri: url.clone(), + diagnostics: vec![], + version: None, + }) + .await; + } + } + async fn execute_command(&self, params: ExecuteCommandParams) -> Result> { let mut string_args = params .arguments