From d576cda7892d5b0407aad4147f0787ca51bf62ce Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Fri, 2 Feb 2024 01:04:27 +0100 Subject: [PATCH] project: Do not inline LSP related methods The way Rust generics works, having a generic argument puts the burden of codegen on the crate that instantiates a generic function, which in our case is an editor. --- crates/project/src/project.rs | 172 ++++++++++++++++++++++++++-------- 1 file changed, 134 insertions(+), 38 deletions(-) diff --git a/crates/project/src/project.rs b/crates/project/src/project.rs index 0788594222..eedfa16e70 100644 --- a/crates/project/src/project.rs +++ b/crates/project/src/project.rs @@ -4414,13 +4414,13 @@ impl Project { } } - pub fn definition( + #[inline(never)] + fn definition_impl( &self, buffer: &Model, - position: T, + position: PointUtf16, cx: &mut ModelContext, ) -> Task>> { - let position = position.to_point_utf16(buffer.read(cx)); self.request_lsp( buffer.clone(), LanguageServerToQuery::Primary, @@ -4428,14 +4428,22 @@ impl Project { cx, ) } - - pub fn type_definition( + pub fn definition( &self, buffer: &Model, position: T, cx: &mut ModelContext, ) -> Task>> { let position = position.to_point_utf16(buffer.read(cx)); + self.definition_impl(buffer, position, cx) + } + + fn type_definition_impl( + &self, + buffer: &Model, + position: PointUtf16, + cx: &mut ModelContext, + ) -> Task>> { self.request_lsp( buffer.clone(), LanguageServerToQuery::Primary, @@ -4443,7 +4451,30 @@ impl Project { cx, ) } + pub fn type_definition( + &self, + buffer: &Model, + position: T, + cx: &mut ModelContext, + ) -> Task>> { + let position = position.to_point_utf16(buffer.read(cx)); + self.type_definition_impl(buffer, position, cx) + } + + fn references_impl( + &self, + buffer: &Model, + position: PointUtf16, + cx: &mut ModelContext, + ) -> Task>> { + self.request_lsp( + buffer.clone(), + LanguageServerToQuery::Primary, + GetReferences { position }, + cx, + ) + } pub fn references( &self, buffer: &Model, @@ -4451,10 +4482,19 @@ impl Project { cx: &mut ModelContext, ) -> Task>> { let position = position.to_point_utf16(buffer.read(cx)); + self.references_impl(buffer, position, cx) + } + + fn document_highlights_impl( + &self, + buffer: &Model, + position: PointUtf16, + cx: &mut ModelContext, + ) -> Task>> { self.request_lsp( buffer.clone(), LanguageServerToQuery::Primary, - GetReferences { position }, + GetDocumentHighlights { position }, cx, ) } @@ -4466,12 +4506,7 @@ impl Project { cx: &mut ModelContext, ) -> Task>> { let position = position.to_point_utf16(buffer.read(cx)); - self.request_lsp( - buffer.clone(), - LanguageServerToQuery::Primary, - GetDocumentHighlights { position }, - cx, - ) + self.document_highlights_impl(buffer, position, cx) } pub fn symbols(&self, query: &str, cx: &mut ModelContext) -> Task>> { @@ -4694,13 +4729,12 @@ impl Project { } } - pub fn hover( + fn hover_impl( &self, buffer: &Model, - position: T, + position: PointUtf16, cx: &mut ModelContext, ) -> Task>> { - let position = position.to_point_utf16(buffer.read(cx)); self.request_lsp( buffer.clone(), LanguageServerToQuery::Primary, @@ -4708,14 +4742,23 @@ impl Project { cx, ) } - - pub fn completions( + pub fn hover( &self, buffer: &Model, position: T, cx: &mut ModelContext, - ) -> Task>> { + ) -> Task>> { let position = position.to_point_utf16(buffer.read(cx)); + self.hover_impl(buffer, position, cx) + } + + #[inline(never)] + fn completions_impl( + &self, + buffer: &Model, + position: PointUtf16, + cx: &mut ModelContext, + ) -> Task>> { if self.is_local() { let snapshot = buffer.read(cx).snapshot(); let offset = position.to_offset(&snapshot); @@ -4762,6 +4805,15 @@ impl Project { Task::ready(Ok(Default::default())) } } + pub fn completions( + &self, + buffer: &Model, + position: T, + cx: &mut ModelContext, + ) -> Task>> { + let position = position.to_point_utf16(buffer.read(cx)); + self.completions_impl(buffer, position, cx) + } pub fn resolve_completions( &self, @@ -5038,6 +5090,20 @@ impl Project { } } + fn code_actions_impl( + &self, + buffer_handle: &Model, + range: Range, + cx: &mut ModelContext, + ) -> Task>> { + self.request_lsp( + buffer_handle.clone(), + LanguageServerToQuery::Primary, + GetCodeActions { range }, + cx, + ) + } + pub fn code_actions( &self, buffer_handle: &Model, @@ -5046,12 +5112,7 @@ impl Project { ) -> Task>> { let buffer = buffer_handle.read(cx); let range = buffer.anchor_before(range.start)..buffer.anchor_before(range.end); - self.request_lsp( - buffer_handle.clone(), - LanguageServerToQuery::Primary, - GetCodeActions { range }, - cx, - ) + self.code_actions_impl(buffer_handle, range, cx) } pub fn apply_code_action( @@ -5420,13 +5481,12 @@ impl Project { Ok(project_transaction) } - pub fn prepare_rename( + fn prepare_rename_impl( &self, buffer: Model, - position: T, + position: PointUtf16, cx: &mut ModelContext, ) -> Task>>> { - let position = position.to_point_utf16(buffer.read(cx)); self.request_lsp( buffer, LanguageServerToQuery::Primary, @@ -5434,11 +5494,20 @@ impl Project { cx, ) } - - pub fn perform_rename( + pub fn prepare_rename( &self, buffer: Model, position: T, + cx: &mut ModelContext, + ) -> Task>>> { + let position = position.to_point_utf16(buffer.read(cx)); + self.prepare_rename_impl(buffer, position, cx) + } + + fn perform_rename_impl( + &self, + buffer: Model, + position: PointUtf16, new_name: String, push_to_history: bool, cx: &mut ModelContext, @@ -5455,22 +5524,28 @@ impl Project { cx, ) } - - pub fn on_type_format( + pub fn perform_rename( &self, buffer: Model, position: T, + new_name: String, + push_to_history: bool, + cx: &mut ModelContext, + ) -> Task> { + let position = position.to_point_utf16(buffer.read(cx)); + self.perform_rename_impl(buffer, position, new_name, push_to_history, cx) + } + + pub fn on_type_format_impl( + &self, + buffer: Model, + position: PointUtf16, trigger: String, push_to_history: bool, cx: &mut ModelContext, ) -> Task>> { - let (position, tab_size) = buffer.update(cx, |buffer, cx| { - let position = position.to_point_utf16(buffer); - ( - position, - language_settings(buffer.language_at(position).as_ref(), buffer.file(), cx) - .tab_size, - ) + let tab_size = buffer.update(cx, |buffer, cx| { + language_settings(buffer.language_at(position).as_ref(), buffer.file(), cx).tab_size }); self.request_lsp( buffer.clone(), @@ -5485,6 +5560,18 @@ impl Project { ) } + pub fn on_type_format( + &self, + buffer: Model, + position: T, + trigger: String, + push_to_history: bool, + cx: &mut ModelContext, + ) -> Task>> { + let position = position.to_point_utf16(buffer.read(cx)); + self.on_type_format_impl(buffer, position, trigger, push_to_history, cx) + } + pub fn inlay_hints( &self, buffer_handle: Model, @@ -5493,6 +5580,15 @@ impl Project { ) -> Task>> { let buffer = buffer_handle.read(cx); let range = buffer.anchor_before(range.start)..buffer.anchor_before(range.end); + self.inlay_hints_impl(buffer_handle, range, cx) + } + fn inlay_hints_impl( + &self, + buffer_handle: Model, + range: Range, + cx: &mut ModelContext, + ) -> Task>> { + let buffer = buffer_handle.read(cx); let range_start = range.start; let range_end = range.end; let buffer_id = buffer.remote_id().into();