Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 26 additions & 31 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jiff = "0.2.24"
itertools = "0.14.0"
line-index = "0.1.2"
lsp-server = "0.7.8"
lsp-types = "0.95"
gen-lsp-types = { version = "0.9", features = ["url"] }
serde-wasm-bindgen = "0.6.5"
wasm-bindgen = "0.2.114"
wasm-bindgen-test = "0.3.50"
Expand Down
1 change: 0 additions & 1 deletion crates/squawk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ anyhow.workspace = true
annotate-snippets.workspace = true
line-index.workspace = true
lsp-server.workspace = true
lsp-types.workspace = true

[dev-dependencies]
insta.workspace = true
Expand Down
3 changes: 2 additions & 1 deletion crates/squawk_server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ anyhow.workspace = true
log.workspace = true
simplelog.workspace = true
lsp-server.workspace = true
lsp-types.workspace = true
gen-lsp-types.workspace = true
url.workspace = true
rowan.workspace = true
salsa.workspace = true
serde.workspace = true
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ pub(crate) struct AssociatedDiagnosticData {
pub(crate) title: String,
/// Edits to fix the diagnostic. If this is empty, a fix
/// does not exist.
pub(crate) edits: Vec<lsp_types::TextEdit>,
pub(crate) edits: Vec<gen_lsp_types::TextEdit>,
/// Edit to ignore the rule the line
pub(crate) ignore_line_edit: Option<lsp_types::TextEdit>,
pub(crate) ignore_line_edit: Option<gen_lsp_types::TextEdit>,
/// Edit to ignore the rule for the file
pub(crate) ignore_file_edit: Option<lsp_types::TextEdit>,
pub(crate) ignore_file_edit: Option<gen_lsp_types::TextEdit>,
}
16 changes: 9 additions & 7 deletions crates/squawk_server/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
use std::panic::UnwindSafe;

use anyhow::Result;
use gen_lsp_types::{Notification as LspNotification, Request as LspRequest};
use log::{error, info};
use lsp_server::{Request, Response};
use lsp_types::{notification::Notification as LspNotification, request::Request as LspRequest};
use salsa::Cancelled;
use serde::{Serialize, de::DeserializeOwned};
use squawk_thread::ThreadIntent;
Expand All @@ -32,9 +32,11 @@ impl<'a> RequestDispatcher<'a> {
where
R: LspRequest,
{
let req = self.req.take_if(|req| req.method.as_str() == R::METHOD)?;
let req = self
.req
.take_if(|req| req.method.as_str() == R::METHOD.as_str())?;
let id = req.id.clone();
match from_json(R::METHOD, &req.params) {
match from_json(R::METHOD.as_str(), &req.params) {
Ok(params) => Some((req, params)),
Err(err) => {
let response = Response::new_err(
Expand Down Expand Up @@ -150,7 +152,7 @@ fn thread_result_to_response<R>(
result: Result<anyhow::Result<R::Result>, PanicError>,
) -> Result<lsp_server::Response, PanicError>
where
R: lsp_types::request::Request,
R: gen_lsp_types::Request,
R::Params: DeserializeOwned,
R::Result: Serialize,
{
Expand Down Expand Up @@ -186,7 +188,7 @@ fn result_to_response<R>(
result: anyhow::Result<R::Result>,
) -> std::result::Result<lsp_server::Response, Cancelled>
where
R: lsp_types::request::Request,
R: gen_lsp_types::Request,
{
match result {
Ok(resp) => Ok(lsp_server::Response::new_ok(id, &resp)),
Expand Down Expand Up @@ -230,9 +232,9 @@ impl<'a> NotificationDispatcher<'a> {
{
let notif = self
.notif
.take_if(|notif| notif.method.as_str() == N::METHOD)?;
.take_if(|notif| notif.method.as_str() == N::METHOD.as_str())?;

match notif.extract(N::METHOD) {
match notif.extract(N::METHOD.as_str()) {
Ok(params) => Some(params),
Err(err) => {
error!("Failed to parse notification params: {err}");
Expand Down
39 changes: 20 additions & 19 deletions crates/squawk_server/src/global_state.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
use std::{num::NonZeroUsize, sync::Arc, time::Instant};

use crossbeam_channel::{Receiver, Sender, select, unbounded};
use gen_lsp_types::Notification as _;
use gen_lsp_types::{
CancelNotification, DidChangeTextDocumentNotification, DidCloseTextDocumentNotification,
DidOpenTextDocumentNotification, ExitNotification,
};
use log::info;
use lsp_server::{Message, Request, Response};
use lsp_types::Url;
use lsp_types::notification::Notification as _;
use lsp_types::notification::{
Cancel, DidChangeTextDocument, DidCloseTextDocument, DidOpenTextDocument,
};
use rustc_hash::FxHashMap;
use salsa::Setter;
use squawk_ide::builtins::{builtins_file, builtins_url};
use squawk_ide::db::{Database, File};
use squawk_thread::TaskPool;
use url::Url;

use lsp_types::request::{
CodeActionRequest, Completion, DocumentDiagnosticRequest, DocumentSymbolRequest,
FoldingRangeRequest, GotoDefinition, HoverRequest, InlayHintRequest, References,
SelectionRangeRequest, SemanticTokensFullRequest, SemanticTokensRangeRequest, Shutdown,
use gen_lsp_types::{
CodeActionRequest, CompletionRequest, DefinitionRequest, DocumentDiagnosticRequest,
DocumentSymbolRequest, FoldingRangeRequest, HoverRequest, InlayHintRequest, ReferencesRequest,
SelectionRangeRequest, SemanticTokensRangeRequest, SemanticTokensRequest, ShutdownRequest,
};

use crate::dispatch::{NotificationDispatcher, RequestDispatcher};
Expand Down Expand Up @@ -161,15 +162,15 @@ impl GlobalState {
Message::Notification(notif) => {
info!("Received notification: method={}", notif.method);

if notif.method == lsp_types::notification::Exit::METHOD {
if notif.method == ExitNotification::METHOD.as_str() {
return Ok(());
}

NotificationDispatcher::new(notif, self)
.on::<Cancel>(handle_cancel)?
.on::<DidOpenTextDocument>(handle_did_open)?
.on::<DidChangeTextDocument>(handle_did_change)?
.on::<DidCloseTextDocument>(handle_did_close)?
.on::<CancelNotification>(handle_cancel)?
.on::<DidOpenTextDocumentNotification>(handle_did_open)?
.on::<DidChangeTextDocumentNotification>(handle_did_change)?
.on::<DidCloseTextDocumentNotification>(handle_did_close)?
.finish();
}
},
Expand Down Expand Up @@ -229,14 +230,14 @@ impl GlobalState {
RequestDispatcher::new(req, self)
// Request handlers that must run on the main thread because they
// mutate GlobalState:
.on_sync_mut::<Shutdown>(handle_shutdown)
.on_sync_mut::<ShutdownRequest>(handle_shutdown)
// Request handlers which are related to the user typing are run on
// the main thread to reduce latency:
.on_sync::<SelectionRangeRequest>(handle_selection_range)
// latency-sensitive but can't run on the main thread due to
// semantic analysis, so we use a higher priority thread
.on_latency_sensitive::<RETRY, Completion>(handle_completion)
.on::<NO_RETRY, GotoDefinition>(handle_goto_definition)
.on_latency_sensitive::<RETRY, CompletionRequest>(handle_completion)
.on::<NO_RETRY, DefinitionRequest>(handle_goto_definition)
.on::<NO_RETRY, HoverRequest>(handle_hover)
.on::<NO_RETRY, CodeActionRequest>(handle_code_action)
.on::<NO_RETRY, InlayHintRequest>(handle_inlay_hints)
Expand All @@ -245,8 +246,8 @@ impl GlobalState {
.on::<NO_RETRY, DocumentDiagnosticRequest>(handle_document_diagnostic)
.on::<NO_RETRY, SyntaxTreeRequest>(handle_syntax_tree)
.on::<NO_RETRY, TokensRequest>(handle_tokens)
.on::<NO_RETRY, References>(handle_references)
.on::<NO_RETRY, SemanticTokensFullRequest>(handle_semantic_tokens_full)
.on::<NO_RETRY, ReferencesRequest>(handle_references)
.on::<NO_RETRY, SemanticTokensRequest>(handle_semantic_tokens_full)
.on::<NO_RETRY, SemanticTokensRangeRequest>(handle_semantic_tokens_range)
.finish();
}
Expand Down
Loading
Loading