Skip to content

Commit 4cb3904

Browse files
committed
Remove redundant file events
1 parent 29970d5 commit 4cb3904

3 files changed

Lines changed: 21 additions & 89 deletions

File tree

crates/ark/src/lsp/backend.rs

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,6 @@ pub(crate) enum LspNotification {
136136
DidChangeTextDocument(DidChangeTextDocumentParams),
137137
DidSaveTextDocument(DidSaveTextDocumentParams),
138138
DidCloseTextDocument(DidCloseTextDocumentParams),
139-
DidCreateFiles(CreateFilesParams),
140-
DidDeleteFiles(DeleteFilesParams),
141-
DidRenameFiles(RenameFilesParams),
142139
}
143140

144141
#[derive(Debug)]
@@ -297,18 +294,6 @@ impl LanguageServer for Backend {
297294
self.notify(LspNotification::DidChangeWatchedFiles(params));
298295
}
299296

300-
async fn did_create_files(&self, params: CreateFilesParams) {
301-
self.notify(LspNotification::DidCreateFiles(params));
302-
}
303-
304-
async fn did_delete_files(&self, params: DeleteFilesParams) {
305-
self.notify(LspNotification::DidDeleteFiles(params));
306-
}
307-
308-
async fn did_rename_files(&self, params: RenameFilesParams) {
309-
self.notify(LspNotification::DidRenameFiles(params));
310-
}
311-
312297
async fn symbol(
313298
&self,
314299
params: WorkspaceSymbolParams,

crates/ark/src/lsp/main_loop.rs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -358,15 +358,6 @@ impl GlobalState {
358358
LspNotification::DidCloseTextDocument(params) => {
359359
state_handlers::did_close(params, &mut self.lsp_state, &mut self.world)?;
360360
},
361-
LspNotification::DidCreateFiles(params) => {
362-
state_handlers::did_create_files(params, &self.world)?;
363-
},
364-
LspNotification::DidDeleteFiles(params) => {
365-
state_handlers::did_delete_files(params, &self.world)?;
366-
},
367-
LspNotification::DidRenameFiles(params) => {
368-
state_handlers::did_rename_files(params, &mut self.world)?;
369-
},
370361
}
371362
},
372363

crates/ark/src/lsp/state_handlers.rs

Lines changed: 21 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ use stdext::result::ResultExt;
1818
use tower_lsp::lsp_types;
1919
use tower_lsp::lsp_types::CompletionOptions;
2020
use tower_lsp::lsp_types::CompletionOptionsCompletionItem;
21-
use tower_lsp::lsp_types::CreateFilesParams;
22-
use tower_lsp::lsp_types::DeleteFilesParams;
2321
use tower_lsp::lsp_types::DidChangeConfigurationParams;
2422
use tower_lsp::lsp_types::DidChangeTextDocumentParams;
2523
use tower_lsp::lsp_types::DidChangeWatchedFilesParams;
@@ -29,18 +27,13 @@ use tower_lsp::lsp_types::DidOpenTextDocumentParams;
2927
use tower_lsp::lsp_types::DocumentOnTypeFormattingOptions;
3028
use tower_lsp::lsp_types::ExecuteCommandOptions;
3129
use tower_lsp::lsp_types::FileChangeType;
32-
use tower_lsp::lsp_types::FileOperationFilter;
33-
use tower_lsp::lsp_types::FileOperationPattern;
34-
use tower_lsp::lsp_types::FileOperationPatternKind;
35-
use tower_lsp::lsp_types::FileOperationRegistrationOptions;
3630
use tower_lsp::lsp_types::FoldingRangeProviderCapability;
3731
use tower_lsp::lsp_types::FormattingOptions;
3832
use tower_lsp::lsp_types::HoverProviderCapability;
3933
use tower_lsp::lsp_types::ImplementationProviderCapability;
4034
use tower_lsp::lsp_types::InitializeParams;
4135
use tower_lsp::lsp_types::InitializeResult;
4236
use tower_lsp::lsp_types::OneOf;
43-
use tower_lsp::lsp_types::RenameFilesParams;
4437
use tower_lsp::lsp_types::RenameOptions;
4538
use tower_lsp::lsp_types::SelectionRangeProviderCapability;
4639
use tower_lsp::lsp_types::ServerCapabilities;
@@ -200,28 +193,11 @@ pub(crate) fn initialize(
200193
supported: Some(true),
201194
change_notifications: Some(OneOf::Left(true)),
202195
}),
203-
file_operations: {
204-
let r_file_filter = FileOperationFilter {
205-
scheme: Some(String::from("file")),
206-
pattern: FileOperationPattern {
207-
glob: String::from("**/*.{r,R}"),
208-
matches: Some(FileOperationPatternKind::File),
209-
options: None,
210-
},
211-
};
212-
Some(lsp_types::WorkspaceFileOperationsServerCapabilities {
213-
did_create: Some(FileOperationRegistrationOptions {
214-
filters: vec![r_file_filter.clone()],
215-
}),
216-
did_delete: Some(FileOperationRegistrationOptions {
217-
filters: vec![r_file_filter.clone()],
218-
}),
219-
did_rename: Some(FileOperationRegistrationOptions {
220-
filters: vec![r_file_filter],
221-
}),
222-
..Default::default()
223-
})
224-
},
196+
// We don't register `file_operations`. Disk changes reach us
197+
// through `didChangeWatchedFiles` from every source (editor, git,
198+
// terminal), so it's the single channel that keeps the index
199+
// current. A rename arrives there as delete + create.
200+
file_operations: None,
225201
}),
226202
document_on_type_formatting_provider: Some(DocumentOnTypeFormattingOptions {
227203
first_trigger_character: String::from("\n"),
@@ -336,54 +312,24 @@ pub(crate) fn did_close(
336312
Ok(())
337313
}
338314

339-
#[tracing::instrument(level = "info", skip_all)]
340-
pub(crate) fn did_create_files(
341-
_params: CreateFilesParams,
342-
_state: &WorldState,
343-
) -> anyhow::Result<()> {
344-
Ok(())
345-
}
346-
347-
#[tracing::instrument(level = "info", skip_all)]
348-
pub(crate) fn did_delete_files(
349-
_params: DeleteFilesParams,
350-
_state: &WorldState,
351-
) -> anyhow::Result<()> {
352-
Ok(())
353-
}
354-
355-
#[tracing::instrument(level = "info", skip_all)]
356-
pub(crate) fn did_rename_files(
357-
_params: RenameFilesParams,
358-
_state: &mut WorldState,
359-
) -> anyhow::Result<()> {
360-
Ok(())
361-
}
362-
363315
#[tracing::instrument(level = "info", skip_all)]
364316
pub(crate) fn did_change_watched_files(
365317
params: DidChangeWatchedFilesParams,
366318
state: &mut WorldState,
367319
lsp_state: &mut LspState,
368320
events_tx: &TokioUnboundedSender<Event>,
369321
) -> anyhow::Result<()> {
370-
// Editor owns the contents of files it has open: Oak should ignore
371-
// disk-side events for those URLs.
322+
// Editor owns the contents of files it has open: ignore disk-side events
323+
// for those URLs. Their content comes from `did_open` / `did_change`.
372324
let editor_owned: HashSet<FilePath> = state.documents.keys().cloned().collect();
373325

374326
let events: Vec<FileEvent> = params
375327
.changes
376-
.into_iter()
377-
.filter_map(|e| {
378-
let kind = match e.typ {
379-
FileChangeType::CREATED => FileEventKind::Created,
380-
FileChangeType::CHANGED => FileEventKind::Changed,
381-
FileChangeType::DELETED => FileEventKind::Deleted,
382-
_ => return None,
383-
};
328+
.iter()
329+
.filter_map(|change| {
384330
Some(FileEvent {
385-
path: FilePath::from_url(&e.uri),
386-
kind,
331+
path: FilePath::from_url(&change.uri),
332+
kind: file_event_kind(change.typ)?,
387333
})
388334
})
389335
.collect();
@@ -393,9 +339,19 @@ pub(crate) fn did_change_watched_files(
393339
.oak_scheduler
394340
.apply_watcher_events(&mut state.db, events, &editor_owned);
395341
dispatch_scan_requests(events_tx, requests);
342+
396343
Ok(())
397344
}
398345

346+
fn file_event_kind(kind: FileChangeType) -> Option<FileEventKind> {
347+
match kind {
348+
FileChangeType::CREATED => Some(FileEventKind::Created),
349+
FileChangeType::CHANGED => Some(FileEventKind::Changed),
350+
FileChangeType::DELETED => Some(FileEventKind::Deleted),
351+
_ => None,
352+
}
353+
}
354+
399355
#[tracing::instrument(level = "info", skip_all)]
400356
pub(crate) fn did_change_workspace_folders(
401357
params: DidChangeWorkspaceFoldersParams,

0 commit comments

Comments
 (0)