Skip to content

Commit

Permalink
very naive implementation
Browse files Browse the repository at this point in the history
Needs a bit of exploration and work.

Ref: #10122
  • Loading branch information
satyarohith committed May 13, 2021
1 parent 5e4764a commit 4f40657
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 0 deletions.
85 changes: 85 additions & 0 deletions cli/lsp/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,91 @@ impl CodeActionCollection {
Ok(())
}

pub(crate) fn add_deno_lint_ignore_action(
&mut self,
specifier: &ModuleSpecifier,
diagnostic: &lsp::Diagnostic,
) -> Result<(), AnyError> {
let code = diagnostic
.code
.as_ref()
.map(|v| match v {
lsp::NumberOrString::String(v) => v.to_owned(),
_ => "".to_string(),
})
.unwrap();

let mut changes = HashMap::new();
HashMap::insert(
&mut changes,
specifier.clone(),
vec![lsp::TextEdit {
new_text: format!("// deno-lint-ignore {}\n", code),
range: lsp::Range {
start: lsp::Position {
line: diagnostic.range.start.line,
character: 0,
},
end: lsp::Position {
line: diagnostic.range.start.line,
character: 0,
},
},
}],
);
let ignore_error_action = lsp::CodeAction {
title: format!("Disable {} for this line", code),
kind: Some(lsp::CodeActionKind::QUICKFIX),
diagnostics: Some(vec![diagnostic.clone()]),
command: None,
is_preferred: None,
disabled: None,
data: None,
edit: Some(lsp::WorkspaceEdit {
changes: Some(changes),
change_annotations: None,
document_changes: None,
}),
};
self.actions.push(CodeActionKind::Deno(ignore_error_action));

let mut changes = HashMap::new();
HashMap::insert(
&mut changes,
specifier.clone(),
vec![lsp::TextEdit {
new_text: "// deno-lint-ignore-file\n".to_string(),
range: lsp::Range {
start: lsp::Position {
line: 0,
character: 0,
},
end: lsp::Position {
line: 0,
character: 0,
},
},
}],
);
let ignore_file_action = lsp::CodeAction {
title: "Disable lint errors for the entire file".to_string(),
kind: Some(lsp::CodeActionKind::QUICKFIX),
diagnostics: Some(vec![diagnostic.clone()]),
command: None,
is_preferred: None,
disabled: None,
data: None,
edit: Some(lsp::WorkspaceEdit {
changes: Some(changes),
change_annotations: None,
document_changes: None,
}),
};
self.actions.push(CodeActionKind::Deno(ignore_file_action));

Ok(())
}

/// Add a TypeScript code fix action to the code actions collection.
pub(crate) async fn add_ts_fix_action(
&mut self,
Expand Down
7 changes: 7 additions & 0 deletions cli/lsp/language_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,6 +941,7 @@ impl Inner {
}
_ => false,
},
"deno-lint" => matches!(&d.code, Some(_)),
"deno" => match &d.code {
Some(NumberOrString::String(code)) => {
code == "no-cache" || code == "no-cache-data"
Expand Down Expand Up @@ -1014,6 +1015,12 @@ impl Inner {
LspError::internal_error()
})?
}
Some("deno-lint") => code_actions
.add_deno_lint_ignore_action(&specifier, diagnostic)
.map_err(|err| {
error!("Unable to fix lint error: {}", err);
LspError::internal_error()
})?,
_ => (),
}
}
Expand Down

0 comments on commit 4f40657

Please sign in to comment.