Use Extension trait in ExtensionLspAdapter (#20704)

This PR updates the `ExtensionLspAdapter` to go through the `Extension`
trait for interacting with extensions rather than going through the
`WasmHost` directly.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-11-14 20:44:57 -05:00 committed by GitHub
parent 332b33716a
commit 1855a312d0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 662 additions and 272 deletions

View file

@ -1,17 +1,20 @@
pub mod extension_builder;
mod extension_manifest;
mod slash_command;
mod types;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use ::lsp::LanguageServerName;
use anyhow::{anyhow, bail, Context as _, Result};
use async_trait::async_trait;
use fs::normalize_path;
use gpui::Task;
use language::LanguageName;
use semantic_version::SemanticVersion;
pub use crate::extension_manifest::*;
pub use crate::slash_command::*;
pub use crate::types::*;
#[async_trait]
pub trait WorktreeDelegate: Send + Sync + 'static {
@ -34,6 +37,43 @@ pub trait Extension: Send + Sync + 'static {
/// Returns the path to this extension's working directory.
fn work_dir(&self) -> Arc<Path>;
/// Returns a path relative to this extension's working directory.
fn path_from_extension(&self, path: &Path) -> PathBuf {
normalize_path(&self.work_dir().join(path))
}
async fn language_server_command(
&self,
language_server_id: LanguageServerName,
language_name: LanguageName,
worktree: Arc<dyn WorktreeDelegate>,
) -> Result<Command>;
async fn language_server_initialization_options(
&self,
language_server_id: LanguageServerName,
language_name: LanguageName,
worktree: Arc<dyn WorktreeDelegate>,
) -> Result<Option<String>>;
async fn language_server_workspace_configuration(
&self,
language_server_id: LanguageServerName,
worktree: Arc<dyn WorktreeDelegate>,
) -> Result<Option<String>>;
async fn labels_for_completions(
&self,
language_server_id: LanguageServerName,
completions: Vec<Completion>,
) -> Result<Vec<Option<CodeLabel>>>;
async fn labels_for_symbols(
&self,
language_server_id: LanguageServerName,
symbols: Vec<Symbol>,
) -> Result<Vec<Option<CodeLabel>>>;
async fn complete_slash_command_argument(
&self,
command: SlashCommand,
@ -44,7 +84,7 @@ pub trait Extension: Send + Sync + 'static {
&self,
command: SlashCommand,
arguments: Vec<String>,
resource: Option<Arc<dyn WorktreeDelegate>>,
worktree: Option<Arc<dyn WorktreeDelegate>>,
) -> Result<SlashCommandOutput>;
async fn suggest_docs_packages(&self, provider: Arc<str>) -> Result<Vec<String>>;

View file

@ -0,0 +1,49 @@
mod lsp;
mod slash_command;
use std::ops::Range;
pub use lsp::*;
pub use slash_command::*;
/// A list of environment variables.
pub type EnvVars = Vec<(String, String)>;
/// A command.
pub struct Command {
/// The command to execute.
pub command: String,
/// The arguments to pass to the command.
pub args: Vec<String>,
/// The environment variables to set for the command.
pub env: EnvVars,
}
/// A label containing some code.
#[derive(Debug, Clone)]
pub struct CodeLabel {
/// The source code to parse with Tree-sitter.
pub code: String,
/// The spans to display in the label.
pub spans: Vec<CodeLabelSpan>,
/// The range of the displayed label to include when filtering.
pub filter_range: Range<usize>,
}
/// A span within a code label.
#[derive(Debug, Clone)]
pub enum CodeLabelSpan {
/// A range into the parsed code.
CodeRange(Range<usize>),
/// A span containing a code literal.
Literal(CodeLabelSpanLiteral),
}
/// A span containing a code literal.
#[derive(Debug, Clone)]
pub struct CodeLabelSpanLiteral {
/// The literal text.
pub text: String,
/// The name of the highlight to use for this literal.
pub highlight_name: Option<String>,
}

View file

@ -0,0 +1,96 @@
use std::option::Option;
/// An LSP completion.
#[derive(Debug, Clone)]
pub struct Completion {
pub label: String,
pub label_details: Option<CompletionLabelDetails>,
pub detail: Option<String>,
pub kind: Option<CompletionKind>,
pub insert_text_format: Option<InsertTextFormat>,
}
/// The kind of an LSP completion.
#[derive(Debug, Clone, Copy)]
pub enum CompletionKind {
Text,
Method,
Function,
Constructor,
Field,
Variable,
Class,
Interface,
Module,
Property,
Unit,
Value,
Enum,
Keyword,
Snippet,
Color,
File,
Reference,
Folder,
EnumMember,
Constant,
Struct,
Event,
Operator,
TypeParameter,
Other(i32),
}
/// Label details for an LSP completion.
#[derive(Debug, Clone)]
pub struct CompletionLabelDetails {
pub detail: Option<String>,
pub description: Option<String>,
}
/// Defines how to interpret the insert text in a completion item.
#[derive(Debug, Clone, Copy)]
pub enum InsertTextFormat {
PlainText,
Snippet,
Other(i32),
}
/// An LSP symbol.
#[derive(Debug, Clone)]
pub struct Symbol {
pub kind: SymbolKind,
pub name: String,
}
/// The kind of an LSP symbol.
#[derive(Debug, Clone, Copy)]
pub enum SymbolKind {
File,
Module,
Namespace,
Package,
Class,
Method,
Property,
Field,
Constructor,
Enum,
Interface,
Function,
Variable,
Constant,
String,
Number,
Boolean,
Array,
Object,
Key,
Null,
EnumMember,
Struct,
Event,
Operator,
TypeParameter,
Other(i32),
}