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
4 changes: 2 additions & 2 deletions crates/squawk_server/src/dispatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ pub(crate) struct RequestDispatcher<'a> {
}

impl<'a> RequestDispatcher<'a> {
pub(crate) fn new(req: lsp_server::Request, system: &'a mut GlobalState) -> Self {
pub(crate) fn new(req: lsp_server::Request, global_state: &'a mut GlobalState) -> Self {
Self {
req: Some(req),
global_state: system,
global_state,
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ use crate::global_state::Snapshot;
use crate::lsp_utils;

pub(crate) fn handle_code_action(
system: &Snapshot,
snapshot: &Snapshot,
params: CodeActionParams,
) -> Result<Option<CodeActionResponse>> {
let uri = params.text_document.uri;

let mut actions: CodeActionResponse = vec![];

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let line_index = line_index(db, file);
let offset = lsp_utils::offset(&line_index, params.range.start).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/completion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::global_state::Snapshot;
use crate::lsp_utils;

pub(crate) fn handle_completion(
system: &Snapshot,
snapshot: &Snapshot,
params: CompletionParams,
) -> Result<Option<CompletionResponse>> {
let uri = params.text_document_position.text_document.uri;
let position = params.text_document_position.position;

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let line_index = line_index(db, file);

let Some(offset) = lsp_utils::offset(&line_index, position) else {
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use lsp_types::{
use crate::global_state::Snapshot;

pub(crate) fn handle_document_diagnostic(
system: &Snapshot,
snapshot: &Snapshot,
params: DocumentDiagnosticParams,
) -> Result<DocumentDiagnosticReportResult> {
let uri = params.text_document.uri;

let diagnostics = system
let diagnostics = snapshot
.file(&uri)
.map(|file| crate::lint::lint(system.db(), file))
.map(|file| crate::lint::lint(snapshot.db(), file))
.unwrap_or_default();

Ok(DocumentDiagnosticReportResult::Report(
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/document_symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ use crate::global_state::Snapshot;
use crate::lsp_utils;

pub(crate) fn handle_document_symbol(
system: &Snapshot,
snapshot: &Snapshot,
params: DocumentSymbolParams,
) -> Result<Option<DocumentSymbolResponse>> {
let uri = params.text_document.uri;

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let line_index = line_index(db, file);

let symbols = document_symbols(db, file);
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/folding_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::global_state::Snapshot;
use crate::lsp_utils;

pub(crate) fn handle_folding_range(
system: &Snapshot,
snapshot: &Snapshot,
params: FoldingRangeParams,
) -> Result<Option<Vec<FoldingRange>>> {
let uri = params.text_document.uri;

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let line_idx = line_index(db, file);

let lsp_folds: Vec<FoldingRange> = folding_ranges(db, file)
Expand Down
8 changes: 4 additions & 4 deletions crates/squawk_server/src/handlers/goto_definition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::global_state::Snapshot;
use crate::lsp_utils::{self, to_location};

pub(crate) fn handle_goto_definition(
system: &Snapshot,
snapshot: &Snapshot,
params: GotoDefinitionParams,
) -> Result<Option<GotoDefinitionResponse>> {
let uri = params.text_document_position_params.text_document.uri;
let position = params.text_document_position_params.position;

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let line_index = line_index(db, file);
let offset = lsp_utils::offset(&line_index, position).unwrap();

Expand All @@ -25,7 +25,7 @@ pub(crate) fn handle_goto_definition(
!location.range.contains(offset),
"Our target destination range must not include the source range otherwise go to def won't work in vscode."
);
to_location(db, system, &uri, location)
to_location(snapshot, &uri, location)
})
.collect();

Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/hover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ use squawk_ide::hover::hover;
use crate::global_state::Snapshot;
use crate::lsp_utils;

pub(crate) fn handle_hover(system: &Snapshot, params: HoverParams) -> Result<Option<Hover>> {
pub(crate) fn handle_hover(snapshot: &Snapshot, params: HoverParams) -> Result<Option<Hover>> {
let uri = params.text_document_position_params.text_document.uri;
let position = params.text_document_position_params.position;

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let line_index = line_index(db, file);
let offset = lsp_utils::offset(&line_index, position).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/inlay_hints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ use crate::global_state::Snapshot;
use crate::lsp_utils;

pub(crate) fn handle_inlay_hints(
system: &Snapshot,
snapshot: &Snapshot,
params: InlayHintParams,
) -> Result<Option<Vec<InlayHint>>> {
let uri = params.text_document.uri;

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let line_index = line_index(db, file);

let hints = inlay_hints(db, file);
Expand Down
8 changes: 4 additions & 4 deletions crates/squawk_server/src/handlers/references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::global_state::Snapshot;
use crate::lsp_utils::{self, to_location};

pub(crate) fn handle_references(
system: &Snapshot,
snapshot: &Snapshot,
params: ReferenceParams,
) -> Result<Option<Vec<Location>>> {
let uri = params.text_document_position.text_document.uri;
let position = params.text_document_position.position;

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let line_index = line_index(db, file);
let offset = lsp_utils::offset(&line_index, position).unwrap();

Expand All @@ -24,7 +24,7 @@ pub(crate) fn handle_references(
let locations: Vec<Location> = refs
.into_iter()
.filter(|loc| include_declaration || !loc.range.contains(offset))
.filter_map(|loc| to_location(db, system, &uri, loc))
.filter_map(|loc| to_location(snapshot, &uri, loc))
.collect();

Ok(Some(locations))
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/selection_range.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ use crate::global_state::Snapshot;
use crate::lsp_utils;

pub(crate) fn handle_selection_range(
system: &Snapshot,
snapshot: &Snapshot,
params: SelectionRangeParams,
) -> Result<Option<Vec<lsp_types::SelectionRange>>> {
let uri = params.text_document.uri;

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let parse = parse(db, file);
let root = parse.syntax_node();
let line_index = line_index(db, file);
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/syntax_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ impl Request for SyntaxTreeRequest {
const METHOD: &'static str = "squawk/syntaxTree";
}

pub(crate) fn handle_syntax_tree(system: &Snapshot, params: SyntaxTreeParams) -> Result<String> {
pub(crate) fn handle_syntax_tree(snapshot: &Snapshot, params: SyntaxTreeParams) -> Result<String> {
let uri = params.text_document.uri;

info!("Generating syntax tree for: {uri}");

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let parse = parse(db, file);
let syntax_tree = format!("{:#?}", parse.syntax_node());

Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/handlers/tokens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ impl Request for TokensRequest {
const METHOD: &'static str = "squawk/tokens";
}

pub(crate) fn handle_tokens(system: &Snapshot, params: TokensParams) -> Result<String> {
pub(crate) fn handle_tokens(snapshot: &Snapshot, params: TokensParams) -> Result<String> {
let uri = params.text_document.uri;

info!("Generating tokens for: {uri}");

let db = system.db();
let file = system.file(&uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(&uri).unwrap();
let content = file.content(db);

// TODO: move this to a tracked function
Expand Down
6 changes: 3 additions & 3 deletions crates/squawk_server/src/lsp_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,12 @@ pub(crate) fn apply_incremental_changes(
}

pub(crate) fn to_location(
db: &dyn salsa::Database,
system: &Snapshot,
snapshot: &Snapshot,
uri: &Url,
loc: squawk_ide::goto_definition::Location,
) -> Option<Location> {
let file = system.file(uri).unwrap();
let db = snapshot.db();
let file = snapshot.file(uri).unwrap();
let uri = match loc.file {
squawk_ide::goto_definition::FileId::Current => uri.clone(),
squawk_ide::goto_definition::FileId::Builtins => builtins_url(db)?,
Expand Down
Loading