mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-08 19:43:11 +00:00
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.
This commit is contained in:
parent
10cd978e93
commit
d576cda789
1 changed files with 134 additions and 38 deletions
|
@ -4414,13 +4414,13 @@ impl Project {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn definition<T: ToPointUtf16>(
|
#[inline(never)]
|
||||||
|
fn definition_impl(
|
||||||
&self,
|
&self,
|
||||||
buffer: &Model<Buffer>,
|
buffer: &Model<Buffer>,
|
||||||
position: T,
|
position: PointUtf16,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Vec<LocationLink>>> {
|
) -> Task<Result<Vec<LocationLink>>> {
|
||||||
let position = position.to_point_utf16(buffer.read(cx));
|
|
||||||
self.request_lsp(
|
self.request_lsp(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
LanguageServerToQuery::Primary,
|
LanguageServerToQuery::Primary,
|
||||||
|
@ -4428,14 +4428,22 @@ impl Project {
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
pub fn definition<T: ToPointUtf16>(
|
||||||
pub fn type_definition<T: ToPointUtf16>(
|
|
||||||
&self,
|
&self,
|
||||||
buffer: &Model<Buffer>,
|
buffer: &Model<Buffer>,
|
||||||
position: T,
|
position: T,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Vec<LocationLink>>> {
|
) -> Task<Result<Vec<LocationLink>>> {
|
||||||
let position = position.to_point_utf16(buffer.read(cx));
|
let position = position.to_point_utf16(buffer.read(cx));
|
||||||
|
self.definition_impl(buffer, position, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn type_definition_impl(
|
||||||
|
&self,
|
||||||
|
buffer: &Model<Buffer>,
|
||||||
|
position: PointUtf16,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Vec<LocationLink>>> {
|
||||||
self.request_lsp(
|
self.request_lsp(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
LanguageServerToQuery::Primary,
|
LanguageServerToQuery::Primary,
|
||||||
|
@ -4443,7 +4451,30 @@ impl Project {
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
pub fn type_definition<T: ToPointUtf16>(
|
||||||
|
&self,
|
||||||
|
buffer: &Model<Buffer>,
|
||||||
|
position: T,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Vec<LocationLink>>> {
|
||||||
|
let position = position.to_point_utf16(buffer.read(cx));
|
||||||
|
|
||||||
|
self.type_definition_impl(buffer, position, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn references_impl(
|
||||||
|
&self,
|
||||||
|
buffer: &Model<Buffer>,
|
||||||
|
position: PointUtf16,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Vec<Location>>> {
|
||||||
|
self.request_lsp(
|
||||||
|
buffer.clone(),
|
||||||
|
LanguageServerToQuery::Primary,
|
||||||
|
GetReferences { position },
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
}
|
||||||
pub fn references<T: ToPointUtf16>(
|
pub fn references<T: ToPointUtf16>(
|
||||||
&self,
|
&self,
|
||||||
buffer: &Model<Buffer>,
|
buffer: &Model<Buffer>,
|
||||||
|
@ -4451,10 +4482,19 @@ impl Project {
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Vec<Location>>> {
|
) -> Task<Result<Vec<Location>>> {
|
||||||
let position = position.to_point_utf16(buffer.read(cx));
|
let position = position.to_point_utf16(buffer.read(cx));
|
||||||
|
self.references_impl(buffer, position, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn document_highlights_impl(
|
||||||
|
&self,
|
||||||
|
buffer: &Model<Buffer>,
|
||||||
|
position: PointUtf16,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Vec<DocumentHighlight>>> {
|
||||||
self.request_lsp(
|
self.request_lsp(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
LanguageServerToQuery::Primary,
|
LanguageServerToQuery::Primary,
|
||||||
GetReferences { position },
|
GetDocumentHighlights { position },
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -4466,12 +4506,7 @@ impl Project {
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Vec<DocumentHighlight>>> {
|
) -> Task<Result<Vec<DocumentHighlight>>> {
|
||||||
let position = position.to_point_utf16(buffer.read(cx));
|
let position = position.to_point_utf16(buffer.read(cx));
|
||||||
self.request_lsp(
|
self.document_highlights_impl(buffer, position, cx)
|
||||||
buffer.clone(),
|
|
||||||
LanguageServerToQuery::Primary,
|
|
||||||
GetDocumentHighlights { position },
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn symbols(&self, query: &str, cx: &mut ModelContext<Self>) -> Task<Result<Vec<Symbol>>> {
|
pub fn symbols(&self, query: &str, cx: &mut ModelContext<Self>) -> Task<Result<Vec<Symbol>>> {
|
||||||
|
@ -4694,13 +4729,12 @@ impl Project {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hover<T: ToPointUtf16>(
|
fn hover_impl(
|
||||||
&self,
|
&self,
|
||||||
buffer: &Model<Buffer>,
|
buffer: &Model<Buffer>,
|
||||||
position: T,
|
position: PointUtf16,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Option<Hover>>> {
|
) -> Task<Result<Option<Hover>>> {
|
||||||
let position = position.to_point_utf16(buffer.read(cx));
|
|
||||||
self.request_lsp(
|
self.request_lsp(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
LanguageServerToQuery::Primary,
|
LanguageServerToQuery::Primary,
|
||||||
|
@ -4708,14 +4742,23 @@ impl Project {
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
pub fn hover<T: ToPointUtf16>(
|
||||||
pub fn completions<T: ToOffset + ToPointUtf16>(
|
|
||||||
&self,
|
&self,
|
||||||
buffer: &Model<Buffer>,
|
buffer: &Model<Buffer>,
|
||||||
position: T,
|
position: T,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Vec<Completion>>> {
|
) -> Task<Result<Option<Hover>>> {
|
||||||
let position = position.to_point_utf16(buffer.read(cx));
|
let position = position.to_point_utf16(buffer.read(cx));
|
||||||
|
self.hover_impl(buffer, position, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(never)]
|
||||||
|
fn completions_impl(
|
||||||
|
&self,
|
||||||
|
buffer: &Model<Buffer>,
|
||||||
|
position: PointUtf16,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Vec<Completion>>> {
|
||||||
if self.is_local() {
|
if self.is_local() {
|
||||||
let snapshot = buffer.read(cx).snapshot();
|
let snapshot = buffer.read(cx).snapshot();
|
||||||
let offset = position.to_offset(&snapshot);
|
let offset = position.to_offset(&snapshot);
|
||||||
|
@ -4762,6 +4805,15 @@ impl Project {
|
||||||
Task::ready(Ok(Default::default()))
|
Task::ready(Ok(Default::default()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn completions<T: ToOffset + ToPointUtf16>(
|
||||||
|
&self,
|
||||||
|
buffer: &Model<Buffer>,
|
||||||
|
position: T,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Vec<Completion>>> {
|
||||||
|
let position = position.to_point_utf16(buffer.read(cx));
|
||||||
|
self.completions_impl(buffer, position, cx)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn resolve_completions(
|
pub fn resolve_completions(
|
||||||
&self,
|
&self,
|
||||||
|
@ -5038,6 +5090,20 @@ impl Project {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn code_actions_impl(
|
||||||
|
&self,
|
||||||
|
buffer_handle: &Model<Buffer>,
|
||||||
|
range: Range<Anchor>,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Vec<CodeAction>>> {
|
||||||
|
self.request_lsp(
|
||||||
|
buffer_handle.clone(),
|
||||||
|
LanguageServerToQuery::Primary,
|
||||||
|
GetCodeActions { range },
|
||||||
|
cx,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn code_actions<T: Clone + ToOffset>(
|
pub fn code_actions<T: Clone + ToOffset>(
|
||||||
&self,
|
&self,
|
||||||
buffer_handle: &Model<Buffer>,
|
buffer_handle: &Model<Buffer>,
|
||||||
|
@ -5046,12 +5112,7 @@ impl Project {
|
||||||
) -> Task<Result<Vec<CodeAction>>> {
|
) -> Task<Result<Vec<CodeAction>>> {
|
||||||
let buffer = buffer_handle.read(cx);
|
let buffer = buffer_handle.read(cx);
|
||||||
let range = buffer.anchor_before(range.start)..buffer.anchor_before(range.end);
|
let range = buffer.anchor_before(range.start)..buffer.anchor_before(range.end);
|
||||||
self.request_lsp(
|
self.code_actions_impl(buffer_handle, range, cx)
|
||||||
buffer_handle.clone(),
|
|
||||||
LanguageServerToQuery::Primary,
|
|
||||||
GetCodeActions { range },
|
|
||||||
cx,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn apply_code_action(
|
pub fn apply_code_action(
|
||||||
|
@ -5420,13 +5481,12 @@ impl Project {
|
||||||
Ok(project_transaction)
|
Ok(project_transaction)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn prepare_rename<T: ToPointUtf16>(
|
fn prepare_rename_impl(
|
||||||
&self,
|
&self,
|
||||||
buffer: Model<Buffer>,
|
buffer: Model<Buffer>,
|
||||||
position: T,
|
position: PointUtf16,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Option<Range<Anchor>>>> {
|
) -> Task<Result<Option<Range<Anchor>>>> {
|
||||||
let position = position.to_point_utf16(buffer.read(cx));
|
|
||||||
self.request_lsp(
|
self.request_lsp(
|
||||||
buffer,
|
buffer,
|
||||||
LanguageServerToQuery::Primary,
|
LanguageServerToQuery::Primary,
|
||||||
|
@ -5434,11 +5494,20 @@ impl Project {
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
pub fn prepare_rename<T: ToPointUtf16>(
|
||||||
pub fn perform_rename<T: ToPointUtf16>(
|
|
||||||
&self,
|
&self,
|
||||||
buffer: Model<Buffer>,
|
buffer: Model<Buffer>,
|
||||||
position: T,
|
position: T,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Option<Range<Anchor>>>> {
|
||||||
|
let position = position.to_point_utf16(buffer.read(cx));
|
||||||
|
self.prepare_rename_impl(buffer, position, cx)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn perform_rename_impl(
|
||||||
|
&self,
|
||||||
|
buffer: Model<Buffer>,
|
||||||
|
position: PointUtf16,
|
||||||
new_name: String,
|
new_name: String,
|
||||||
push_to_history: bool,
|
push_to_history: bool,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
|
@ -5455,22 +5524,28 @@ impl Project {
|
||||||
cx,
|
cx,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
pub fn perform_rename<T: ToPointUtf16>(
|
||||||
pub fn on_type_format<T: ToPointUtf16>(
|
|
||||||
&self,
|
&self,
|
||||||
buffer: Model<Buffer>,
|
buffer: Model<Buffer>,
|
||||||
position: T,
|
position: T,
|
||||||
|
new_name: String,
|
||||||
|
push_to_history: bool,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<ProjectTransaction>> {
|
||||||
|
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<Buffer>,
|
||||||
|
position: PointUtf16,
|
||||||
trigger: String,
|
trigger: String,
|
||||||
push_to_history: bool,
|
push_to_history: bool,
|
||||||
cx: &mut ModelContext<Self>,
|
cx: &mut ModelContext<Self>,
|
||||||
) -> Task<Result<Option<Transaction>>> {
|
) -> Task<Result<Option<Transaction>>> {
|
||||||
let (position, tab_size) = buffer.update(cx, |buffer, cx| {
|
let tab_size = buffer.update(cx, |buffer, cx| {
|
||||||
let position = position.to_point_utf16(buffer);
|
language_settings(buffer.language_at(position).as_ref(), buffer.file(), cx).tab_size
|
||||||
(
|
|
||||||
position,
|
|
||||||
language_settings(buffer.language_at(position).as_ref(), buffer.file(), cx)
|
|
||||||
.tab_size,
|
|
||||||
)
|
|
||||||
});
|
});
|
||||||
self.request_lsp(
|
self.request_lsp(
|
||||||
buffer.clone(),
|
buffer.clone(),
|
||||||
|
@ -5485,6 +5560,18 @@ impl Project {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn on_type_format<T: ToPointUtf16>(
|
||||||
|
&self,
|
||||||
|
buffer: Model<Buffer>,
|
||||||
|
position: T,
|
||||||
|
trigger: String,
|
||||||
|
push_to_history: bool,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<Result<Option<Transaction>>> {
|
||||||
|
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<T: ToOffset>(
|
pub fn inlay_hints<T: ToOffset>(
|
||||||
&self,
|
&self,
|
||||||
buffer_handle: Model<Buffer>,
|
buffer_handle: Model<Buffer>,
|
||||||
|
@ -5493,6 +5580,15 @@ impl Project {
|
||||||
) -> Task<anyhow::Result<Vec<InlayHint>>> {
|
) -> Task<anyhow::Result<Vec<InlayHint>>> {
|
||||||
let buffer = buffer_handle.read(cx);
|
let buffer = buffer_handle.read(cx);
|
||||||
let range = buffer.anchor_before(range.start)..buffer.anchor_before(range.end);
|
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<Buffer>,
|
||||||
|
range: Range<Anchor>,
|
||||||
|
cx: &mut ModelContext<Self>,
|
||||||
|
) -> Task<anyhow::Result<Vec<InlayHint>>> {
|
||||||
|
let buffer = buffer_handle.read(cx);
|
||||||
let range_start = range.start;
|
let range_start = range.start;
|
||||||
let range_end = range.end;
|
let range_end = range.end;
|
||||||
let buffer_id = buffer.remote_id().into();
|
let buffer_id = buffer.remote_id().into();
|
||||||
|
|
Loading…
Reference in a new issue