mirror of
https://github.com/astral-sh/ruff.git
synced 2025-11-19 20:24:27 +00:00
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (${{ github.repository == 'astral-sh/ruff' && 'depot-windows-2022-16' || 'windows-latest' }}) (push) Blocked by required conditions
CI / cargo test (macos-latest) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / ty completion evaluation (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks instrumented (ruff) (push) Blocked by required conditions
CI / benchmarks instrumented (ty) (push) Blocked by required conditions
CI / benchmarks walltime (medium|multithreaded) (push) Blocked by required conditions
CI / benchmarks walltime (small|large) (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
51 lines
1.7 KiB
Rust
51 lines
1.7 KiB
Rust
//! Utility functions common to language server request handlers
|
|
//! that return symbol information.
|
|
|
|
use lsp_types::{SymbolInformation, SymbolKind};
|
|
use ty_ide::SymbolInfo;
|
|
|
|
use crate::Db;
|
|
use crate::document::{PositionEncoding, ToRangeExt};
|
|
|
|
/// Convert `ty_ide` `SymbolKind` to LSP `SymbolKind`
|
|
pub(crate) fn convert_symbol_kind(kind: ty_ide::SymbolKind) -> SymbolKind {
|
|
match kind {
|
|
ty_ide::SymbolKind::Module => SymbolKind::MODULE,
|
|
ty_ide::SymbolKind::Class => SymbolKind::CLASS,
|
|
ty_ide::SymbolKind::Method => SymbolKind::METHOD,
|
|
ty_ide::SymbolKind::Function => SymbolKind::FUNCTION,
|
|
ty_ide::SymbolKind::Variable => SymbolKind::VARIABLE,
|
|
ty_ide::SymbolKind::Constant => SymbolKind::CONSTANT,
|
|
ty_ide::SymbolKind::Property => SymbolKind::PROPERTY,
|
|
ty_ide::SymbolKind::Field => SymbolKind::FIELD,
|
|
ty_ide::SymbolKind::Constructor => SymbolKind::CONSTRUCTOR,
|
|
ty_ide::SymbolKind::Parameter => SymbolKind::VARIABLE,
|
|
ty_ide::SymbolKind::TypeParameter => SymbolKind::TYPE_PARAMETER,
|
|
ty_ide::SymbolKind::Import => SymbolKind::MODULE,
|
|
}
|
|
}
|
|
|
|
/// Convert a `ty_ide` `SymbolInfo` to LSP `SymbolInformation`
|
|
pub(crate) fn convert_to_lsp_symbol_information(
|
|
db: &dyn Db,
|
|
file: ruff_db::files::File,
|
|
symbol: SymbolInfo<'_>,
|
|
encoding: PositionEncoding,
|
|
) -> Option<SymbolInformation> {
|
|
let symbol_kind = convert_symbol_kind(symbol.kind);
|
|
|
|
let location = symbol
|
|
.full_range
|
|
.as_lsp_range(db, file, encoding)
|
|
.to_location()?;
|
|
|
|
Some(SymbolInformation {
|
|
name: symbol.name.into_owned(),
|
|
kind: symbol_kind,
|
|
tags: None,
|
|
#[allow(deprecated)]
|
|
deprecated: None,
|
|
location,
|
|
container_name: None,
|
|
})
|
|
}
|