ResolvedAssist, Runnable, Severity, SourceChange, SourceFileEdit, TextEdit,
};
use ra_syntax::{SyntaxKind, TextRange, TextSize};
-use ra_vfs::LineEndings;
use crate::{
- cargo_target_spec::CargoTargetSpec, global_state::GlobalStateSnapshot, lsp_ext,
- semantic_tokens, Result,
+ cargo_target_spec::CargoTargetSpec, global_state::GlobalStateSnapshot,
+ line_endings::LineEndings, lsp_ext, semantic_tokens, Result,
};
pub(crate) fn position(line_index: &LineIndex, offset: TextSize) -> lsp_types::Position {
HighlightTag::SelfType => lsp_types::SemanticTokenType::TYPE,
HighlightTag::Field => lsp_types::SemanticTokenType::PROPERTY,
HighlightTag::Function => lsp_types::SemanticTokenType::FUNCTION,
+ HighlightTag::Generic => semantic_tokens::GENERIC,
HighlightTag::Module => lsp_types::SemanticTokenType::NAMESPACE,
HighlightTag::Constant => {
mods |= semantic_tokens::CONSTANT;
HighlightTag::UnresolvedReference => semantic_tokens::UNRESOLVED_REFERENCE,
HighlightTag::FormatSpecifier => semantic_tokens::FORMAT_SPECIFIER,
HighlightTag::Operator => lsp_types::SemanticTokenType::OPERATOR,
+ HighlightTag::EscapeSequence => semantic_tokens::ESCAPE_SEQUENCE,
};
for modifier in highlight.modifiers.iter() {
let modifier = match modifier {
HighlightModifier::Attribute => semantic_tokens::ATTRIBUTE_MODIFIER,
HighlightModifier::Definition => lsp_types::SemanticTokenModifier::DECLARATION,
+ HighlightModifier::Documentation => lsp_types::SemanticTokenModifier::DOCUMENTATION,
+ HighlightModifier::Injected => semantic_tokens::INJECTED,
HighlightModifier::ControlFlow => semantic_tokens::CONTROL_FLOW,
HighlightModifier::Mutable => semantic_tokens::MUTABLE,
HighlightModifier::Unsafe => semantic_tokens::UNSAFE,
let kind = match fold.kind {
FoldKind::Comment => Some(lsp_types::FoldingRangeKind::Comment),
FoldKind::Imports => Some(lsp_types::FoldingRangeKind::Imports),
- FoldKind::Mods | FoldKind::Block => None,
+ FoldKind::Mods | FoldKind::Block | FoldKind::ArgList => None,
};
let range = range(line_index, fold.range);
frange: FileRange,
) -> Result<lsp_types::Location> {
let url = url(snap, frange.file_id);
- let line_index = snap.analysis().file_line_index(frange.file_id)?;
+ let line_index = snap.analysis.file_line_index(frange.file_id)?;
let range = range(&line_index, frange.range);
let loc = lsp_types::Location::new(url, range);
Ok(loc)
}
+/// Perefer using `location_link`, if the client has the cap.
+pub(crate) fn location_from_nav(
+ snap: &GlobalStateSnapshot,
+ nav: NavigationTarget,
+) -> Result<lsp_types::Location> {
+ let url = url(snap, nav.file_id());
+ let line_index = snap.analysis.file_line_index(nav.file_id())?;
+ let range = range(&line_index, nav.full_range());
+ let loc = lsp_types::Location::new(url, range);
+ Ok(loc)
+}
+
pub(crate) fn location_link(
snap: &GlobalStateSnapshot,
src: Option<FileRange>,
) -> Result<lsp_types::LocationLink> {
let origin_selection_range = match src {
Some(src) => {
- let line_index = snap.analysis().file_line_index(src.file_id)?;
+ let line_index = snap.analysis.file_line_index(src.file_id)?;
let range = range(&line_index, src.range);
Some(range)
}
snap: &GlobalStateSnapshot,
target: NavigationTarget,
) -> Result<(lsp_types::Url, lsp_types::Range, lsp_types::Range)> {
- let line_index = snap.analysis().file_line_index(target.file_id())?;
+ let line_index = snap.analysis.file_line_index(target.file_id())?;
let target_uri = url(snap, target.file_id());
let target_range = range(&line_index, target.full_range());
source_file_edit: SourceFileEdit,
) -> Result<lsp_ext::SnippetTextDocumentEdit> {
let text_document = versioned_text_document_identifier(snap, source_file_edit.file_id, None);
- let line_index = snap.analysis().file_line_index(source_file_edit.file_id)?;
+ let line_index = snap.analysis.file_line_index(source_file_edit.file_id)?;
let line_endings = snap.file_line_endings(source_file_edit.file_id);
let edits = source_file_edit
.edit
runnable: Runnable,
) -> Result<lsp_ext::Runnable> {
let spec = CargoTargetSpec::for_file(snap, file_id)?;
+ let workspace_root = spec.as_ref().map(|it| it.workspace_root.clone());
let target = spec.as_ref().map(|s| s.target.clone());
let (cargo_args, executable_args) =
- CargoTargetSpec::runnable_args(spec, &runnable.kind, &runnable.cfg_exprs)?;
+ CargoTargetSpec::runnable_args(snap, spec, &runnable.kind, &runnable.cfg_exprs)?;
let label = runnable.label(target);
let location = location_link(snap, None, runnable.nav)?;
location: Some(location),
kind: lsp_ext::RunnableKind::Cargo,
args: lsp_ext::CargoRunnable {
- workspace_root: snap.workspace_root_for(file_id).map(|root| root.to_owned()),
+ workspace_root: workspace_root.map(|it| it.into()),
cargo_args,
executable_args,
+ expect_test: None,
},
})
}
#[cfg(test)]
mod tests {
- use test_utils::extract_ranges;
+ use ra_ide::Analysis;
use super::*;
#[test]
fn conv_fold_line_folding_only_fixup() {
- let text = r#"<fold>mod a;
+ let text = r#"mod a;
mod b;
-mod c;</fold>
+mod c;
-fn main() <fold>{
- if cond <fold>{
+fn main() {
+ if cond {
a::do_a();
- }</fold> else <fold>{
+ } else {
b::do_b();
- }</fold>
-}</fold>"#;
-
- let (ranges, text) = extract_ranges(text, "fold");
- assert_eq!(ranges.len(), 4);
- let folds = vec![
- Fold { range: ranges[0], kind: FoldKind::Mods },
- Fold { range: ranges[1], kind: FoldKind::Block },
- Fold { range: ranges[2], kind: FoldKind::Block },
- Fold { range: ranges[3], kind: FoldKind::Block },
- ];
+ }
+}"#;
+
+ let (analysis, file_id) = Analysis::from_single_file(text.to_string());
+ let folds = analysis.folding_ranges(file_id).unwrap();
+ assert_eq!(folds.len(), 4);
let line_index = LineIndex::new(&text);
let converted: Vec<lsp_types::FoldingRange> =