Skip to content

Commit

Permalink
language: Update buffer doc comments (#18646)
Browse files Browse the repository at this point in the history
This PR updates the doc comments in `buffer.rs` to use the standard
style for linking to other items.

Release Notes:

- N/A
  • Loading branch information
maxdeviant authored Oct 2, 2024
1 parent 209ebb0 commit 0e82765
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions crates/language/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub use lsp::DiagnosticSeverity;
/// a diff against the contents of its file.
pub static BUFFER_DIFF_TASK: LazyLock<TaskLabel> = LazyLock::new(TaskLabel::new);

/// Indicate whether a [Buffer] has permissions to edit.
/// Indicate whether a [`Buffer`] has permissions to edit.
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum Capability {
/// The buffer is a mutable replica.
Expand Down Expand Up @@ -211,7 +211,7 @@ pub struct Diagnostic {
///
/// When a language server produces a diagnostic with
/// one or more associated diagnostics, those diagnostics are all
/// assigned a single group id.
/// assigned a single group ID.
pub group_id: usize,
/// Whether this diagnostic is the primary diagnostic for its group.
///
Expand Down Expand Up @@ -718,7 +718,7 @@ impl Buffer {
self
}

/// Returns the [Capability] of this buffer.
/// Returns the [`Capability`] of this buffer.
pub fn capability(&self) -> Capability {
self.capability
}
Expand All @@ -728,7 +728,7 @@ impl Buffer {
self.capability == Capability::ReadOnly
}

/// Builds a [Buffer] with the given underlying [TextBuffer], diff base, [File] and [Capability].
/// Builds a [`Buffer`] with the given underlying [`TextBuffer`], diff base, [`File`] and [`Capability`].
pub fn build(
buffer: TextBuffer,
diff_base: Option<String>,
Expand Down Expand Up @@ -941,7 +941,7 @@ impl Buffer {
self.syntax_map.lock().language_registry()
}

/// Assign the buffer a new [Capability].
/// Assign the buffer a new [`Capability`].
pub fn set_capability(&mut self, capability: Capability, cx: &mut ModelContext<Self>) {
self.capability = capability;
cx.emit(BufferEvent::CapabilityChanged)
Expand Down Expand Up @@ -1032,7 +1032,7 @@ impl Buffer {
cx.notify();
}

/// Updates the [File] backing this buffer. This should be called when
/// Updates the [`File`] backing this buffer. This should be called when
/// the file has changed or has been deleted.
pub fn file_updated(&mut self, new_file: Arc<dyn File>, cx: &mut ModelContext<Self>) {
let mut file_changed = false;
Expand Down Expand Up @@ -1071,7 +1071,7 @@ impl Buffer {
}
}

/// Returns the current diff base, see [Buffer::set_diff_base].
/// Returns the current diff base, see [`Buffer::set_diff_base`].
pub fn diff_base(&self) -> Option<&Rope> {
match self.diff_base.as_ref()? {
BufferDiffBase::Git(rope) | BufferDiffBase::PastBufferVersion { rope, .. } => {
Expand Down Expand Up @@ -1142,12 +1142,12 @@ impl Buffer {
}))
}

/// Returns the primary [Language] assigned to this [Buffer].
/// Returns the primary [`Language`] assigned to this [`Buffer`].
pub fn language(&self) -> Option<&Arc<Language>> {
self.language.as_ref()
}

/// Returns the [Language] at the given location.
/// Returns the [`Language`] at the given location.
pub fn language_at<D: ToOffset>(&self, position: D) -> Option<Arc<Language>> {
let offset = position.to_offset(self);
self.syntax_map
Expand Down Expand Up @@ -2730,6 +2730,7 @@ impl BufferSnapshot {
.collect();
(captures, highlight_maps)
}

/// 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`](text::Rope). The text is also
/// returned in chunks where each chunk has a single syntax highlighting style and
Expand Down Expand Up @@ -2781,12 +2782,12 @@ impl BufferSnapshot {
.last()
}

/// Returns the main [Language]
/// Returns the main [`Language`].
pub fn language(&self) -> Option<&Arc<Language>> {
self.language.as_ref()
}

/// Returns the [Language] at the given location.
/// Returns the [`Language`] at the given location.
pub fn language_at<D: ToOffset>(&self, position: D) -> Option<&Arc<Language>> {
self.syntax_layer_at(position)
.map(|info| info.language)
Expand All @@ -2806,7 +2807,7 @@ impl BufferSnapshot {
CharClassifier::new(self.language_scope_at(point))
}

/// Returns the [LanguageScope] at the given location.
/// Returns the [`LanguageScope`] at the given location.
pub fn language_scope_at<D: ToOffset>(&self, position: D) -> Option<LanguageScope> {
let offset = position.to_offset(self);
let mut scope = None;
Expand Down Expand Up @@ -2961,7 +2962,7 @@ impl BufferSnapshot {

/// Returns the outline for the buffer.
///
/// This method allows passing an optional [SyntaxTheme] to
/// This method allows passing an optional [`SyntaxTheme`] to
/// syntax-highlight the returned symbols.
pub fn outline(&self, theme: Option<&SyntaxTheme>) -> Option<Outline<Anchor>> {
self.outline_items_containing(0..self.len(), true, theme)
Expand All @@ -2970,7 +2971,7 @@ impl BufferSnapshot {

/// Returns all the symbols that contain the given position.
///
/// This method allows passing an optional [SyntaxTheme] to
/// This method allows passing an optional [`SyntaxTheme`] to
/// syntax-highlight the returned symbols.
pub fn symbols_containing<T: ToOffset>(
&self,
Expand Down Expand Up @@ -3213,7 +3214,7 @@ impl BufferSnapshot {
}

/// For each grammar in the language, runs the provided
/// [tree_sitter::Query] against the given range.
/// [`tree_sitter::Query`] against the given range.
pub fn matches(
&self,
range: Range<usize>,
Expand Down Expand Up @@ -3774,7 +3775,7 @@ impl BufferSnapshot {
})
}

/// Whether the buffer contains any git changes.
/// Whether the buffer contains any Git changes.
pub fn has_git_diff(&self) -> bool {
!self.git_diff.is_empty()
}
Expand Down Expand Up @@ -3856,7 +3857,7 @@ impl BufferSnapshot {
}

/// Returns all the diagnostic groups associated with the given
/// language server id. If no language server id is provided,
/// language server ID. If no language server ID is provided,
/// all diagnostics groups are returned.
pub fn diagnostic_groups(
&self,
Expand Down Expand Up @@ -4239,36 +4240,36 @@ impl Default for Diagnostic {
}

impl IndentSize {
/// Returns an [IndentSize] representing the given spaces.
/// Returns an [`IndentSize`] representing the given spaces.
pub fn spaces(len: u32) -> Self {
Self {
len,
kind: IndentKind::Space,
}
}

/// Returns an [IndentSize] representing a tab.
/// Returns an [`IndentSize`] representing a tab.
pub fn tab() -> Self {
Self {
len: 1,
kind: IndentKind::Tab,
}
}

/// An iterator over the characters represented by this [IndentSize].
/// An iterator over the characters represented by this [`IndentSize`].
pub fn chars(&self) -> impl Iterator<Item = char> {
iter::repeat(self.char()).take(self.len as usize)
}

/// The character representation of this [IndentSize].
/// The character representation of this [`IndentSize`].
pub fn char(&self) -> char {
match self.kind {
IndentKind::Space => ' ',
IndentKind::Tab => '\t',
}
}

/// Consumes the current [IndentSize] and returns a new one that has
/// Consumes the current [`IndentSize`] and returns a new one that has
/// been shrunk or enlarged by the given size along the given direction.
pub fn with_delta(mut self, direction: Ordering, size: IndentSize) -> Self {
match direction {
Expand Down

0 comments on commit 0e82765

Please sign in to comment.