summaryrefslogtreecommitdiff
path: root/cli/lsp
diff options
context:
space:
mode:
Diffstat (limited to 'cli/lsp')
-rw-r--r--cli/lsp/analysis.rs8
-rw-r--r--cli/lsp/diagnostics.rs46
-rw-r--r--cli/lsp/documents.rs2
-rw-r--r--cli/lsp/tsc.rs35
4 files changed, 39 insertions, 52 deletions
diff --git a/cli/lsp/analysis.rs b/cli/lsp/analysis.rs
index 4c087cfa2..3359fc666 100644
--- a/cli/lsp/analysis.rs
+++ b/cli/lsp/analysis.rs
@@ -274,7 +274,7 @@ pub fn analyze_dependencies(
let resolved_import =
resolve_import(&import, specifier, maybe_import_map);
if media_type == &MediaType::JavaScript
- || media_type == &MediaType::JSX
+ || media_type == &MediaType::Jsx
{
maybe_type = Some(resolved_import)
} else {
@@ -297,11 +297,7 @@ pub fn analyze_dependencies(
let maybe_resolved_type_dependency =
// Check for `@deno-types` pragmas that affect the import
if let Some(comment) = desc.leading_comments.last() {
- if let Some(deno_types) = parse_deno_types(&comment.text).as_ref() {
- Some(resolve_import(deno_types, specifier, maybe_import_map))
- } else {
- None
- }
+ parse_deno_types(&comment.text).as_ref().map(|deno_types| resolve_import(deno_types, specifier, maybe_import_map))
} else {
None
};
diff --git a/cli/lsp/diagnostics.rs b/cli/lsp/diagnostics.rs
index f720299d7..d4ec3d494 100644
--- a/cli/lsp/diagnostics.rs
+++ b/cli/lsp/diagnostics.rs
@@ -461,31 +461,27 @@ fn get_diagnostic_message(diagnostic: &diagnostics::Diagnostic) -> String {
fn to_lsp_related_information(
related_information: &Option<Vec<diagnostics::Diagnostic>>,
) -> Option<Vec<lsp::DiagnosticRelatedInformation>> {
- if let Some(related) = related_information {
- Some(
- related
- .iter()
- .filter_map(|ri| {
- if let (Some(source), Some(start), Some(end)) =
- (&ri.source, &ri.start, &ri.end)
- {
- let uri = lsp::Url::parse(&source).unwrap();
- Some(lsp::DiagnosticRelatedInformation {
- location: lsp::Location {
- uri,
- range: to_lsp_range(start, end),
- },
- message: get_diagnostic_message(&ri),
- })
- } else {
- None
- }
- })
- .collect(),
- )
- } else {
- None
- }
+ related_information.as_ref().map(|related| {
+ related
+ .iter()
+ .filter_map(|ri| {
+ if let (Some(source), Some(start), Some(end)) =
+ (&ri.source, &ri.start, &ri.end)
+ {
+ let uri = lsp::Url::parse(&source).unwrap();
+ Some(lsp::DiagnosticRelatedInformation {
+ location: lsp::Location {
+ uri,
+ range: to_lsp_range(start, end),
+ },
+ message: get_diagnostic_message(&ri),
+ })
+ } else {
+ None
+ }
+ })
+ .collect()
+ })
}
fn ts_json_to_diagnostics(
diff --git a/cli/lsp/documents.rs b/cli/lsp/documents.rs
index da393fbac..47a23eb49 100644
--- a/cli/lsp/documents.rs
+++ b/cli/lsp/documents.rs
@@ -154,7 +154,7 @@ impl DocumentCache {
}
pub fn len(&self) -> usize {
- self.docs.iter().count()
+ self.docs.len()
}
pub fn line_index(&self, specifier: &ModuleSpecifier) -> Option<LineIndex> {
diff --git a/cli/lsp/tsc.rs b/cli/lsp/tsc.rs
index 7569036f5..d3fec5d64 100644
--- a/cli/lsp/tsc.rs
+++ b/cli/lsp/tsc.rs
@@ -166,11 +166,7 @@ pub async fn get_asset(
.request(state_snapshot, RequestMethod::GetAsset(specifier.clone()))
.await?;
let maybe_text: Option<String> = serde_json::from_value(res)?;
- let maybe_asset = if let Some(text) = maybe_text {
- Some(AssetDocument::new(text))
- } else {
- None
- };
+ let maybe_asset = maybe_text.map(AssetDocument::new);
Ok(maybe_asset)
}
}
@@ -183,7 +179,7 @@ fn display_parts_to_string(parts: &[SymbolDisplayPart]) -> String {
.join("")
}
-fn get_tag_body_text(tag: &JSDocTagInfo) -> Option<String> {
+fn get_tag_body_text(tag: &JsDocTagInfo) -> Option<String> {
tag.text.as_ref().map(|text| match tag.name.as_str() {
"example" => {
let caption_regex =
@@ -209,7 +205,7 @@ fn get_tag_body_text(tag: &JSDocTagInfo) -> Option<String> {
})
}
-fn get_tag_documentation(tag: &JSDocTagInfo) -> String {
+fn get_tag_documentation(tag: &JsDocTagInfo) -> String {
match tag.name.as_str() {
"augments" | "extends" | "param" | "template" => {
if let Some(text) = &tag.text {
@@ -439,7 +435,7 @@ pub struct SymbolDisplayPart {
#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
-pub struct JSDocTagInfo {
+pub struct JsDocTagInfo {
name: String,
text: Option<String>,
}
@@ -452,7 +448,7 @@ pub struct QuickInfo {
text_span: TextSpan,
display_parts: Option<Vec<SymbolDisplayPart>>,
documentation: Option<Vec<SymbolDisplayPart>>,
- tags: Option<Vec<JSDocTagInfo>>,
+ tags: Option<Vec<JsDocTagInfo>>,
}
impl QuickInfo {
@@ -536,10 +532,11 @@ impl DocumentSpan {
let origin_selection_range =
if let Some(original_context_span) = &self.original_context_span {
Some(original_context_span.to_range(line_index))
- } else if let Some(original_text_span) = &self.original_text_span {
- Some(original_text_span.to_range(line_index))
} else {
- None
+ self
+ .original_text_span
+ .as_ref()
+ .map(|original_text_span| original_text_span.to_range(line_index))
};
let link = lsp::LocationLink {
origin_selection_range,
@@ -927,7 +924,7 @@ pub struct CompletionEntryDetails {
kind_modifiers: String,
display_parts: Vec<SymbolDisplayPart>,
documentation: Option<Vec<SymbolDisplayPart>>,
- tags: Option<Vec<JSDocTagInfo>>,
+ tags: Option<Vec<JsDocTagInfo>>,
code_actions: Option<Vec<CodeAction>>,
source: Option<Vec<SymbolDisplayPart>>,
}
@@ -1261,7 +1258,7 @@ pub struct SignatureHelpItem {
separator_display_parts: Vec<SymbolDisplayPart>,
parameters: Vec<SignatureHelpParameter>,
documentation: Vec<SymbolDisplayPart>,
- tags: Vec<JSDocTagInfo>,
+ tags: Vec<JsDocTagInfo>,
}
impl SignatureHelpItem {
@@ -1328,12 +1325,9 @@ impl SelectionRange {
) -> lsp::SelectionRange {
lsp::SelectionRange {
range: self.text_span.to_range(line_index),
- parent: match &self.parent {
- Some(parent_selection) => {
- Some(Box::new(parent_selection.to_selection_range(line_index)))
- }
- None => None,
- },
+ parent: self.parent.as_ref().map(|parent_selection| {
+ Box::new(parent_selection.to_selection_range(line_index))
+ }),
}
}
}
@@ -1345,6 +1339,7 @@ struct Response {
}
struct State<'a> {
+ #[allow(unused)]
asset: Option<String>,
last_id: usize,
response: Option<Response>,