From b02f37083b2e703cadb6752ba75ed7f8be626d15 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Tue, 9 Jan 2024 10:53:57 -0800 Subject: [PATCH] More docs --- crates/language/src/buffer.rs | 26 +++++++++--- crates/language/src/language.rs | 32 ++++++++++++--- crates/language/src/language_settings.rs | 33 +++++++++++++-- crates/language/src/outline.rs | 1 + crates/language/src/proto.rs | 41 +++++++++++++++---- crates/language/src/syntax_map.rs | 36 ++++++++-------- crates/language_tools/src/syntax_tree_view.rs | 6 +-- 7 files changed, 133 insertions(+), 42 deletions(-) diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index f4917780b3..b745ff6f43 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -10,7 +10,7 @@ use crate::{ markdown::parse_markdown, outline::OutlineItem, syntax_map::{ - SyntaxLayerInfo, SyntaxMap, SyntaxMapCapture, SyntaxMapCaptures, SyntaxMapMatches, + SyntaxLayer, SyntaxMap, SyntaxMapCapture, SyntaxMapCaptures, SyntaxMapMatches, SyntaxSnapshot, ToTreeSitterPoint, }, CodeLabel, LanguageScope, Outline, @@ -69,7 +69,8 @@ pub enum Capability { ReadOnly, } -/// An in-memory representation of a source code file. +/// An in-memory representation of a source code file, including its text, +/// syntax trees, git status, and diagnostics. pub struct Buffer { text: TextBuffer, diff_base: Option, @@ -123,12 +124,15 @@ pub struct BufferSnapshot { parse_count: usize, } +/// The kind and amount of indentation in a particular line. For now, +/// assumes that indentation is all the same character. #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub struct IndentSize { pub len: u32, pub kind: IndentKind, } +/// A whitespace character that's used for indentation. #[derive(Clone, Copy, Debug, PartialEq, Eq, Default)] pub enum IndentKind { #[default] @@ -136,6 +140,7 @@ pub enum IndentKind { Tab, } +/// The shape of a selection cursor. #[derive(Copy, Clone, PartialEq, Eq, Debug, Default)] pub enum CursorShape { #[default] @@ -300,6 +305,7 @@ pub trait File: Send + Sync { fn to_proto(&self) -> rpc::proto::File; } +/// The file associated with a buffer, in the case where the file is on the local disk. pub trait LocalFile: File { /// Returns the absolute path of this file. fn abs_path(&self, cx: &AppContext) -> PathBuf; @@ -409,6 +415,7 @@ pub(crate) struct DiagnosticEndpoint { is_unnecessary: bool, } +/// A class of characters, used for characterizing a run of text. #[derive(Copy, Clone, Eq, PartialEq, PartialOrd, Ord, Debug)] pub enum CharKind { Whitespace, @@ -2048,6 +2055,8 @@ impl BufferSnapshot { } } + /// Retrieve the suggested indent size for all of the given rows. The unit of indentation + /// is passed in as `single_indent_size`. pub fn suggested_indents( &self, rows: impl Iterator, @@ -2294,6 +2303,10 @@ impl BufferSnapshot { None } + /// Iterates over chunks of text in the given range of the buffer. Text is chunked + /// in an arbitrary way due to being stored in a [`rope::Rope`]. The text is also + /// returned in chunks where each chunk has a single syntax highlighting style and + /// diagnostic status. pub fn chunks(&self, range: Range, language_aware: bool) -> BufferChunks { let range = range.start.to_offset(self)..range.end.to_offset(self); @@ -2330,7 +2343,9 @@ impl BufferSnapshot { BufferChunks::new(self.text.as_rope(), range, syntax, diagnostic_endpoints) } - pub fn for_each_line(&self, range: Range, mut callback: impl FnMut(u32, &str)) { + /// Invokes the given callback for each line of text in the given range of the buffer. + /// Uses callback to avoid allocating a string for each line. + fn for_each_line(&self, range: Range, mut callback: impl FnMut(u32, &str)) { let mut line = String::new(); let mut row = range.start.row; for chunk in self @@ -2349,11 +2364,12 @@ impl BufferSnapshot { } } - pub fn syntax_layers(&self) -> impl Iterator + '_ { + /// Iterates over every [`SyntaxLayer`] in the buffer. + pub fn syntax_layers(&self) -> impl Iterator + '_ { self.syntax.layers_for_range(0..self.len(), &self.text) } - pub fn syntax_layer_at(&self, position: D) -> Option { + pub fn syntax_layer_at(&self, position: D) -> Option { let offset = position.to_offset(self); self.syntax .layers_for_range(offset..offset, &self.text) diff --git a/crates/language/src/language.rs b/crates/language/src/language.rs index df12a270c9..8182af1e54 100644 --- a/crates/language/src/language.rs +++ b/crates/language/src/language.rs @@ -58,7 +58,7 @@ pub use buffer::*; pub use diagnostic_set::DiagnosticEntry; pub use lsp::LanguageServerId; pub use outline::{Outline, OutlineItem}; -pub use syntax_map::{OwnedSyntaxLayerInfo, SyntaxLayerInfo}; +pub use syntax_map::{OwnedSyntaxLayer, SyntaxLayer}; pub use text::LineEnding; pub use tree_sitter::{Parser, Tree}; @@ -246,6 +246,8 @@ impl CachedLspAdapter { } } +/// [`LspAdapterDelegate`] allows [`LspAdapter]` implementations to interface with the application +// e.g. to display a notification or fetch data from the web. pub trait LspAdapterDelegate: Send + Sync { fn show_notification(&self, message: &str, cx: &mut AppContext); fn http_client(&self) -> Arc; @@ -291,6 +293,10 @@ pub trait LspAdapter: 'static + Send + Sync { delegate: &dyn LspAdapterDelegate, ) -> Option; + /// Returns true if a language server can be reinstalled. + /// If language server initialization fails, a reinstallation will be attempted unless the value returned from this method is false. + /// Implementations that rely on software already installed on user's system + /// should have [`can_be_reinstalled`] return false. fn can_be_reinstalled(&self) -> bool { true } @@ -302,6 +308,9 @@ pub trait LspAdapter: 'static + Send + Sync { fn process_diagnostics(&self, _: &mut lsp::PublishDiagnosticsParams) {} + /// A callback called for each [`lsp_types::CompletionItem`] obtained from LSP server. + /// Some LspAdapter implementations might want to modify the obtained item to + /// change how it's displayed. async fn process_completion(&self, _: &mut lsp::CompletionItem) {} async fn label_for_completion( @@ -321,6 +330,7 @@ pub trait LspAdapter: 'static + Send + Sync { None } + /// Returns initialization options that are going to be sent to a LSP server as a part of [`lsp_types::InitializeParams`] async fn initialization_options(&self) -> Option { None } @@ -329,6 +339,7 @@ pub trait LspAdapter: 'static + Send + Sync { futures::future::ready(serde_json::json!({})).boxed() } + /// Returns a list of code actions supported by a given LspAdapter fn code_action_kinds(&self) -> Option> { Some(vec![ CodeActionKind::EMPTY, @@ -380,19 +391,29 @@ pub struct LanguageConfig { /// the indentation level for a new line. #[serde(default = "auto_indent_using_last_non_empty_line_default")] pub auto_indent_using_last_non_empty_line: bool, - /// A regex that is used to determine whether the + /// A regex that is used to determine whether the indentation level should be + /// increased in the following line. #[serde(default, deserialize_with = "deserialize_regex")] pub increase_indent_pattern: Option, + /// A regex that is used to determine whether the indentation level should be + /// decreased in the following line. #[serde(default, deserialize_with = "deserialize_regex")] pub decrease_indent_pattern: Option, + /// A list of characters that trigger the automatic insertion of a closing + /// bracket when they immediately precede the point where an opening + /// bracket is inserted. #[serde(default)] pub autoclose_before: String, - #[serde(default)] - pub line_comment: Option>, + /// A placeholder used internally by Semantic Index. #[serde(default)] pub collapsed_placeholder: String, + /// A line comment string that is inserted in e.g. `toggle comments` action. + #[serde(default)] + pub line_comment: Option>, + /// Starting and closing characters of a block comment. #[serde(default)] pub block_comment: Option<(Arc, Arc)>, + /// A list of language servers that are allowed to run on subranges of a given language. #[serde(default)] pub scope_opt_in_language_servers: Vec, #[serde(default)] @@ -402,6 +423,7 @@ pub struct LanguageConfig { /// or a whole-word search in buffer search. #[serde(default)] pub word_characters: HashSet, + /// The name of a Prettier parser that should be used for this language. #[serde(default)] pub prettier_parser_name: Option, } @@ -480,9 +502,9 @@ impl Default for LanguageConfig { block_comment: Default::default(), scope_opt_in_language_servers: Default::default(), overrides: Default::default(), - collapsed_placeholder: Default::default(), word_characters: Default::default(), prettier_parser_name: None, + collapsed_placeholder: Default::default(), } } } diff --git a/crates/language/src/language_settings.rs b/crates/language/src/language_settings.rs index 3ac8842243..c1bd3aa57f 100644 --- a/crates/language/src/language_settings.rs +++ b/crates/language/src/language_settings.rs @@ -96,24 +96,30 @@ pub struct LanguageSettings { /// The settings for [GitHub Copilot](https://github.com/features/copilot). #[derive(Clone, Debug, Default)] pub struct CopilotSettings { - /// Whether Copilit is enabled. + /// Whether Copilot is enabled. pub feature_enabled: bool, /// A list of globs representing files that Copilot should be disabled for. pub disabled_globs: Vec, } +/// The settings for all languages. #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] pub struct AllLanguageSettingsContent { + /// The settings for enabling/disabling features. #[serde(default)] pub features: Option, + /// The settings for GitHub Copilot. #[serde(default)] pub copilot: Option, + /// The default language settings. #[serde(flatten)] pub defaults: LanguageSettingsContent, + /// The settings for individual languages. #[serde(default, alias = "language_overrides")] pub languages: HashMap, LanguageSettingsContent>, } +/// The settings for a particular language. #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] pub struct LanguageSettingsContent { /// How many columns a tab should occupy. @@ -204,12 +210,15 @@ pub struct LanguageSettingsContent { pub inlay_hints: Option, } +/// The contents of the GitHub Copilot settings. #[derive(Clone, Debug, Default, Serialize, Deserialize, JsonSchema)] pub struct CopilotSettingsContent { + /// A list of globs representing files that Copilot should be disabled for. #[serde(default)] pub disabled_globs: Option>, } +/// The settings for enabling/disabling features. #[derive(Clone, Default, Serialize, Deserialize, JsonSchema)] #[serde(rename_all = "snake_case")] pub struct FeaturesContent { @@ -237,6 +246,7 @@ pub enum FormatOnSave { On, /// Files should not be formatted on save. Off, + /// Files should be formatted using the current language server. LanguageServer, /// The external program to use to format the files on save. External { @@ -247,17 +257,19 @@ pub enum FormatOnSave { }, } +/// Controls how whitespace should be displayedin the editor. #[derive(Copy, Clone, Debug, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum ShowWhitespaceSetting { - /// Draw tabs and spaces only for the selected text. + /// Draw whitespace only for the selected text. Selection, - /// Do not draw any tabs or spaces + /// Do not draw any tabs or spaces. None, - /// Draw all invisible symbols + /// Draw all invisible symbols. All, } +/// Controls which formatter should be used when formatting code. #[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq, JsonSchema)] #[serde(rename_all = "snake_case")] pub enum Formatter { @@ -271,7 +283,9 @@ pub enum Formatter { Prettier, /// Format code using an external command. External { + /// The external program to run. command: Arc, + /// The arguments to pass to the program. arguments: Arc<[String]>, }, } @@ -323,6 +337,7 @@ impl InlayHintSettings { } impl AllLanguageSettings { + /// Returns the [`LanguageSettings`] for the language with the specified name. pub fn language<'a>(&'a self, language_name: Option<&str>) -> &'a LanguageSettings { if let Some(name) = language_name { if let Some(overrides) = self.languages.get(name) { @@ -332,6 +347,7 @@ impl AllLanguageSettings { &self.defaults } + /// Returns whether GitHub Copilot is enabled for the given path. pub fn copilot_enabled_for_path(&self, path: &Path) -> bool { !self .copilot @@ -340,6 +356,7 @@ impl AllLanguageSettings { .any(|glob| glob.is_match(path)) } + /// Returns whether GitHub Copilot is enabled for the given language and path. pub fn copilot_enabled(&self, language: Option<&Arc>, path: Option<&Path>) -> bool { if !self.copilot.feature_enabled { return false; @@ -356,13 +373,20 @@ impl AllLanguageSettings { } } +/// The kind of an inlay hint. #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum InlayHintKind { + /// An inlay hint for a type. Type, + /// An inlay hint for a parameter. Parameter, } impl InlayHintKind { + /// Returns the [`InlayHintKind`] from the given name. + /// + /// Returns `None` if `name` does not match any of the expected + /// string representations. pub fn from_name(name: &str) -> Option { match name { "type" => Some(InlayHintKind::Type), @@ -371,6 +395,7 @@ impl InlayHintKind { } } + /// Returns the name of this [`InlayHintKind`]. pub fn name(&self) -> &'static str { match self { InlayHintKind::Type => "type", diff --git a/crates/language/src/outline.rs b/crates/language/src/outline.rs index df1a3c629e..014b32676a 100644 --- a/crates/language/src/outline.rs +++ b/crates/language/src/outline.rs @@ -2,6 +2,7 @@ use fuzzy::{StringMatch, StringMatchCandidate}; use gpui::{BackgroundExecutor, HighlightStyle}; use std::ops::Range; +/// An outline of all the symbols contained in a buffer. #[derive(Debug)] pub struct Outline { pub items: Vec>, diff --git a/crates/language/src/proto.rs b/crates/language/src/proto.rs index 8d71e6e397..0497a4c459 100644 --- a/crates/language/src/proto.rs +++ b/crates/language/src/proto.rs @@ -13,18 +13,18 @@ use text::*; pub use proto::{BufferState, Operation}; -/// Serializes a [`RopeFingerprint`] to be sent over the wire. +/// Serializes a [`RopeFingerprint`] to be sent over RPC. pub fn serialize_fingerprint(fingerprint: RopeFingerprint) -> String { fingerprint.to_hex() } -/// Deserializes a [`RopeFingerprint`] from the wire format. +/// Deserializes a [`RopeFingerprint`] from the RPC representation. pub fn deserialize_fingerprint(fingerprint: &str) -> Result { RopeFingerprint::from_hex(fingerprint) .map_err(|error| anyhow!("invalid fingerprint: {}", error)) } -/// Deserializes a `[text::LineEnding]` from the wire format. +/// Deserializes a `[text::LineEnding]` from the RPC representation. pub fn deserialize_line_ending(message: proto::LineEnding) -> text::LineEnding { match message { proto::LineEnding::Unix => text::LineEnding::Unix, @@ -32,7 +32,7 @@ pub fn deserialize_line_ending(message: proto::LineEnding) -> text::LineEnding { } } -/// Serializes a [`text::LineEnding`] to be sent over the wire. +/// Serializes a [`text::LineEnding`] to be sent over RPC. pub fn serialize_line_ending(message: text::LineEnding) -> proto::LineEnding { match message { text::LineEnding::Unix => proto::LineEnding::Unix, @@ -40,7 +40,7 @@ pub fn serialize_line_ending(message: text::LineEnding) -> proto::LineEnding { } } -/// Serializes a [`crate::Operation`] to be sent over the wire. +/// Serializes a [`crate::Operation`] to be sent over RPC. pub fn serialize_operation(operation: &crate::Operation) -> proto::Operation { proto::Operation { variant: Some(match operation { @@ -103,7 +103,7 @@ pub fn serialize_operation(operation: &crate::Operation) -> proto::Operation { } } -/// Serializes an [`operation::EditOperation`] to be sent over the wire. +/// Serializes an [`operation::EditOperation`] to be sent over RPC. pub fn serialize_edit_operation(operation: &EditOperation) -> proto::operation::Edit { proto::operation::Edit { replica_id: operation.timestamp.replica_id as u32, @@ -118,7 +118,7 @@ pub fn serialize_edit_operation(operation: &EditOperation) -> proto::operation:: } } -/// Serializes an entry in the undo map to be sent over the wire. +/// Serializes an entry in the undo map to be sent over RPC. pub fn serialize_undo_map_entry( (edit_id, counts): (&clock::Lamport, &[(clock::Lamport, u32)]), ) -> proto::UndoMapEntry { @@ -136,6 +136,7 @@ pub fn serialize_undo_map_entry( } } +/// Splits the given list of operations into chunks. pub fn split_operations( mut operations: Vec, ) -> impl Iterator> { @@ -161,10 +162,12 @@ pub fn split_operations( }) } +/// Serializes selections to be sent over RPC. pub fn serialize_selections(selections: &Arc<[Selection]>) -> Vec { selections.iter().map(serialize_selection).collect() } +/// Serializes a [`Selection`] to be sent over RPC. pub fn serialize_selection(selection: &Selection) -> proto::Selection { proto::Selection { id: selection.id as u64, @@ -180,6 +183,7 @@ pub fn serialize_selection(selection: &Selection) -> proto::Selection { } } +/// Serializes a [`CursorShape`] to be sent over RPC. pub fn serialize_cursor_shape(cursor_shape: &CursorShape) -> proto::CursorShape { match cursor_shape { CursorShape::Bar => proto::CursorShape::CursorBar, @@ -189,6 +193,7 @@ pub fn serialize_cursor_shape(cursor_shape: &CursorShape) -> proto::CursorShape } } +/// Deserializes a [`CursorShape`] from the RPC representation. pub fn deserialize_cursor_shape(cursor_shape: proto::CursorShape) -> CursorShape { match cursor_shape { proto::CursorShape::CursorBar => CursorShape::Bar, @@ -198,6 +203,7 @@ pub fn deserialize_cursor_shape(cursor_shape: proto::CursorShape) -> CursorShape } } +/// Serializes a list of diagnostics to be sent over RPC. pub fn serialize_diagnostics<'a>( diagnostics: impl IntoIterator>, ) -> Vec { @@ -225,6 +231,7 @@ pub fn serialize_diagnostics<'a>( .collect() } +/// Serializes an [`Anchor`] to be sent over RPC. pub fn serialize_anchor(anchor: &Anchor) -> proto::Anchor { proto::Anchor { replica_id: anchor.timestamp.replica_id as u32, @@ -239,6 +246,7 @@ pub fn serialize_anchor(anchor: &Anchor) -> proto::Anchor { } // This behavior is currently copied in the collab database, for snapshotting channel notes +/// Deserializes an [`crate::Operation`] from the RPC representation. pub fn deserialize_operation(message: proto::Operation) -> Result { Ok( match message @@ -321,6 +329,7 @@ pub fn deserialize_operation(message: proto::Operation) -> Result EditOperation { EditOperation { timestamp: clock::Lamport { @@ -333,6 +342,7 @@ pub fn deserialize_edit_operation(edit: proto::operation::Edit) -> EditOperation } } +/// Deserializes an entry in the undo map from the RPC representation. pub fn deserialize_undo_map_entry( entry: proto::UndoMapEntry, ) -> (clock::Lamport, Vec<(clock::Lamport, u32)>) { @@ -357,6 +367,7 @@ pub fn deserialize_undo_map_entry( ) } +/// Deserializes selections from the RPC representation. pub fn deserialize_selections(selections: Vec) -> Arc<[Selection]> { Arc::from( selections @@ -366,6 +377,7 @@ pub fn deserialize_selections(selections: Vec) -> Arc<[Selecti ) } +/// Deserializes a [`Selection`] from the RPC representation. pub fn deserialize_selection(selection: proto::Selection) -> Option> { Some(Selection { id: selection.id as usize, @@ -376,6 +388,7 @@ pub fn deserialize_selection(selection: proto::Selection) -> Option, ) -> Arc<[DiagnosticEntry]> { @@ -406,6 +419,7 @@ pub fn deserialize_diagnostics( .collect() } +/// Deserializes an [`Anchor`] from the RPC representation. pub fn deserialize_anchor(anchor: proto::Anchor) -> Option { Some(Anchor { timestamp: clock::Lamport { @@ -421,6 +435,7 @@ pub fn deserialize_anchor(anchor: proto::Anchor) -> Option { }) } +/// Returns a `[clock::Lamport`] timestamp for the given [`proto::Operation`]. pub fn lamport_timestamp_for_operation(operation: &proto::Operation) -> Option { let replica_id; let value; @@ -453,6 +468,7 @@ pub fn lamport_timestamp_for_operation(operation: &proto::Operation) -> Option proto::Completion { proto::Completion { old_start: Some(serialize_anchor(&completion.old_range.start)), @@ -463,6 +479,7 @@ pub fn serialize_completion(completion: &Completion) -> proto::Completion { } } +/// Deserializes a [`Completion`] from the RPC representation. pub async fn deserialize_completion( completion: proto::Completion, language: Option>, @@ -497,6 +514,7 @@ pub async fn deserialize_completion( }) } +/// Serializes a [`CodeAction`] to be sent over RPC. pub fn serialize_code_action(action: &CodeAction) -> proto::CodeAction { proto::CodeAction { server_id: action.server_id.0 as u64, @@ -506,6 +524,7 @@ pub fn serialize_code_action(action: &CodeAction) -> proto::CodeAction { } } +/// Deserializes a [`CodeAction`] from the RPC representation. pub fn deserialize_code_action(action: proto::CodeAction) -> Result { let start = action .start @@ -523,6 +542,7 @@ pub fn deserialize_code_action(action: proto::CodeAction) -> Result }) } +/// Serializes a [`Transaction`] to be sent over RPC. pub fn serialize_transaction(transaction: &Transaction) -> proto::Transaction { proto::Transaction { id: Some(serialize_timestamp(transaction.id)), @@ -536,6 +556,7 @@ pub fn serialize_transaction(transaction: &Transaction) -> proto::Transaction { } } +/// Deserializes a [`Transaction`] from the RPC representation. pub fn deserialize_transaction(transaction: proto::Transaction) -> Result { Ok(Transaction { id: deserialize_timestamp( @@ -552,6 +573,7 @@ pub fn deserialize_transaction(transaction: proto::Transaction) -> Result proto::LamportTimestamp { proto::LamportTimestamp { replica_id: timestamp.replica_id as u32, @@ -559,6 +581,7 @@ pub fn serialize_timestamp(timestamp: clock::Lamport) -> proto::LamportTimestamp } } +/// Deserializes a [`clock::Lamport`] timestamp from the RPC representation. pub fn deserialize_timestamp(timestamp: proto::LamportTimestamp) -> clock::Lamport { clock::Lamport { replica_id: timestamp.replica_id as ReplicaId, @@ -566,6 +589,7 @@ pub fn deserialize_timestamp(timestamp: proto::LamportTimestamp) -> clock::Lampo } } +/// Serializes a range of [`FullOffset`]s to be sent over RPC. pub fn serialize_range(range: &Range) -> proto::Range { proto::Range { start: range.start.0 as u64, @@ -573,10 +597,12 @@ pub fn serialize_range(range: &Range) -> proto::Range { } } +/// Deserializes a range of [`FullOffset`]s from the RPC representation. pub fn deserialize_range(range: proto::Range) -> Range { FullOffset(range.start as usize)..FullOffset(range.end as usize) } +/// Deserializes a clock version from the RPC representation. pub fn deserialize_version(message: &[proto::VectorClockEntry]) -> clock::Global { let mut version = clock::Global::new(); for entry in message { @@ -588,6 +614,7 @@ pub fn deserialize_version(message: &[proto::VectorClockEntry]) -> clock::Global version } +/// Serializes a clock version to be sent over RPC. pub fn serialize_version(version: &clock::Global) -> Vec { version .iter() diff --git a/crates/language/src/syntax_map.rs b/crates/language/src/syntax_map.rs index c22ece48af..9174dc7df9 100644 --- a/crates/language/src/syntax_map.rs +++ b/crates/language/src/syntax_map.rs @@ -29,7 +29,7 @@ pub struct SyntaxMap { #[derive(Clone, Default)] pub struct SyntaxSnapshot { - layers: SumTree, + layers: SumTree, parsed_version: clock::Global, interpolated_version: clock::Global, language_registry_version: usize, @@ -84,7 +84,7 @@ struct SyntaxMapMatchesLayer<'a> { } #[derive(Clone)] -struct SyntaxLayer { +struct SyntaxLayerEntry { depth: usize, range: Range, content: SyntaxLayerContent, @@ -118,7 +118,7 @@ impl SyntaxLayerContent { } #[derive(Debug)] -pub struct SyntaxLayerInfo<'a> { +pub struct SyntaxLayer<'a> { pub depth: usize, pub language: &'a Arc, tree: &'a Tree, @@ -126,7 +126,7 @@ pub struct SyntaxLayerInfo<'a> { } #[derive(Clone)] -pub struct OwnedSyntaxLayerInfo { +pub struct OwnedSyntaxLayer { pub depth: usize, pub language: Arc, tree: tree_sitter::Tree, @@ -691,7 +691,7 @@ impl SyntaxSnapshot { }; layers.push( - SyntaxLayer { + SyntaxLayerEntry { depth: step.depth, range: step.range, content, @@ -741,7 +741,7 @@ impl SyntaxSnapshot { SyntaxMapCaptures::new( range.clone(), text, - [SyntaxLayerInfo { + [SyntaxLayer { language, tree, depth: 0, @@ -781,7 +781,7 @@ impl SyntaxSnapshot { } #[cfg(test)] - pub fn layers<'a>(&'a self, buffer: &'a BufferSnapshot) -> Vec { + pub fn layers<'a>(&'a self, buffer: &'a BufferSnapshot) -> Vec { self.layers_for_range(0..buffer.len(), buffer).collect() } @@ -789,7 +789,7 @@ impl SyntaxSnapshot { &'a self, range: Range, buffer: &'a BufferSnapshot, - ) -> impl 'a + Iterator { + ) -> impl 'a + Iterator { let start_offset = range.start.to_offset(buffer); let end_offset = range.end.to_offset(buffer); let start = buffer.anchor_before(start_offset); @@ -813,7 +813,7 @@ impl SyntaxSnapshot { let layer_start_offset = layer.range.start.to_offset(buffer); let layer_start_point = layer.range.start.to_point(buffer).to_ts_point(); - info = Some(SyntaxLayerInfo { + info = Some(SyntaxLayer { tree, language, depth: layer.depth, @@ -842,7 +842,7 @@ impl<'a> SyntaxMapCaptures<'a> { fn new( range: Range, text: &'a Rope, - layers: impl Iterator>, + layers: impl Iterator>, query: fn(&Grammar) -> Option<&Query>, ) -> Self { let mut result = Self { @@ -964,7 +964,7 @@ impl<'a> SyntaxMapMatches<'a> { fn new( range: Range, text: &'a Rope, - layers: impl Iterator>, + layers: impl Iterator>, query: fn(&Grammar) -> Option<&Query>, ) -> Self { let mut result = Self::default(); @@ -1436,16 +1436,16 @@ fn insert_newlines_between_ranges( } } -impl OwnedSyntaxLayerInfo { +impl OwnedSyntaxLayer { pub fn node(&self) -> Node { self.tree .root_node_with_offset(self.offset.0, self.offset.1) } } -impl<'a> SyntaxLayerInfo<'a> { - pub fn to_owned(&self) -> OwnedSyntaxLayerInfo { - OwnedSyntaxLayerInfo { +impl<'a> SyntaxLayer<'a> { + pub fn to_owned(&self) -> OwnedSyntaxLayer { + OwnedSyntaxLayer { tree: self.tree.clone(), offset: self.offset, depth: self.depth, @@ -1564,7 +1564,7 @@ impl ChangeRegionSet { ) } - fn intersects(&self, layer: &SyntaxLayer, text: &BufferSnapshot) -> bool { + fn intersects(&self, layer: &SyntaxLayerEntry, text: &BufferSnapshot) -> bool { for region in &self.0 { if region.depth < layer.depth { continue; @@ -1675,7 +1675,7 @@ impl<'a> SeekTarget<'a, SyntaxLayerSummary, SyntaxLayerSummary> } } -impl sum_tree::Item for SyntaxLayer { +impl sum_tree::Item for SyntaxLayerEntry { type Summary = SyntaxLayerSummary; fn summary(&self) -> Self::Summary { @@ -1690,7 +1690,7 @@ impl sum_tree::Item for SyntaxLayer { } } -impl std::fmt::Debug for SyntaxLayer { +impl std::fmt::Debug for SyntaxLayerEntry { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("SyntaxLayer") .field("depth", &self.depth) diff --git a/crates/language_tools/src/syntax_tree_view.rs b/crates/language_tools/src/syntax_tree_view.rs index c30564e9bf..493ce162cb 100644 --- a/crates/language_tools/src/syntax_tree_view.rs +++ b/crates/language_tools/src/syntax_tree_view.rs @@ -5,7 +5,7 @@ use gpui::{ MouseButton, MouseDownEvent, MouseMoveEvent, ParentElement, Pixels, Render, Styled, UniformListScrollHandle, View, ViewContext, VisualContext, WeakView, WindowContext, }; -use language::{Buffer, OwnedSyntaxLayerInfo}; +use language::{Buffer, OwnedSyntaxLayer}; use settings::Settings; use std::{mem, ops::Range}; use theme::{ActiveTheme, ThemeSettings}; @@ -57,7 +57,7 @@ struct EditorState { struct BufferState { buffer: Model, excerpt_id: ExcerptId, - active_layer: Option, + active_layer: Option, } impl SyntaxTreeView { @@ -491,7 +491,7 @@ impl SyntaxTreeToolbarItemView { }) } - fn render_header(active_layer: &OwnedSyntaxLayerInfo) -> ButtonLike { + fn render_header(active_layer: &OwnedSyntaxLayer) -> ButtonLike { ButtonLike::new("syntax tree header") .child(Label::new(active_layer.language.name())) .child(Label::new(format_node_range(active_layer.node())))