mirror of
https://github.com/Automattic/harper.git
synced 2025-12-05 19:26:55 -06:00
fix(ls): use code key in diagnostics (#2254)
This commit is contained in:
@@ -5,8 +5,8 @@ use harper_core::{CharStringExt, Document};
|
||||
use harper_stats::RecordKind;
|
||||
use serde_json::Value;
|
||||
use tower_lsp_server::lsp_types::{
|
||||
CodeAction, CodeActionKind, CodeActionOrCommand, Command, Diagnostic, TextEdit, Uri,
|
||||
WorkspaceEdit,
|
||||
CodeAction, CodeActionKind, CodeActionOrCommand, Command, Diagnostic, NumberOrString, TextEdit,
|
||||
Uri, WorkspaceEdit,
|
||||
};
|
||||
|
||||
use crate::config::{CodeActionConfig, DiagnosticSeverity};
|
||||
@@ -131,9 +131,9 @@ fn lint_to_diagnostic(
|
||||
Diagnostic {
|
||||
range,
|
||||
severity: Some(severity.to_lsp()),
|
||||
code: None,
|
||||
code_description: None,
|
||||
source: Some(format!("Harper ({})", origin_tag)),
|
||||
source: Some("Harper".to_owned()),
|
||||
code: Some(NumberOrString::String(origin_tag.to_string())),
|
||||
message: lint.message.clone(),
|
||||
related_information: None,
|
||||
tags: None,
|
||||
|
||||
@@ -48,7 +48,7 @@ export async function setTextDocumentLanguage(uri: Uri, languageId: string): Pro
|
||||
}
|
||||
|
||||
export function createExpectedDiagnostics(
|
||||
...data: { message: string; range: Range; source: string }[]
|
||||
...data: { message: string; range: Range; source: string; code: string }[]
|
||||
): Diagnostic[] {
|
||||
return data.map((d) => ({ ...d, severity: DiagnosticSeverity.Information }));
|
||||
}
|
||||
|
||||
@@ -37,17 +37,20 @@ describe('Integration >', () => {
|
||||
{
|
||||
message: 'Did you mean to repeat this word?',
|
||||
range: createRange(2, 39, 2, 48),
|
||||
source: 'Harper (RepeatedWords)',
|
||||
source: 'Harper',
|
||||
code: 'RepeatedWords',
|
||||
},
|
||||
{
|
||||
message: 'Did you mean to spell `errorz` this way?',
|
||||
range: createRange(2, 26, 2, 32),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
},
|
||||
{
|
||||
message: 'Did you mean to spell `realise` this way?',
|
||||
range: createRange(4, 26, 4, 33),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -61,7 +64,8 @@ describe('Integration >', () => {
|
||||
createExpectedDiagnostics({
|
||||
message: 'Did you mean to spell `Errorz` this way?',
|
||||
range: createRange(0, 0, 0, 6),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -78,12 +82,14 @@ describe('Integration >', () => {
|
||||
{
|
||||
message: 'Did you mean to spell `Errorz` this way?',
|
||||
range: createRange(0, 0, 0, 6),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
},
|
||||
{
|
||||
message: 'Did you mean to spell `Errorz` this way?',
|
||||
range: createRange(0, 9, 0, 15),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -96,7 +102,8 @@ describe('Integration >', () => {
|
||||
createExpectedDiagnostics({
|
||||
message: 'Did you mean to spell `Errorz` this way?',
|
||||
range: createRange(0, 9, 0, 15),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
}),
|
||||
);
|
||||
});
|
||||
@@ -113,12 +120,14 @@ describe('Integration >', () => {
|
||||
{
|
||||
message: 'Did you mean to spell `errorz` this way?',
|
||||
range: createRange(2, 26, 2, 32),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
},
|
||||
{
|
||||
message: 'Did you mean to spell `realise` this way?',
|
||||
range: createRange(4, 26, 4, 33),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
},
|
||||
),
|
||||
);
|
||||
@@ -142,12 +151,14 @@ describe('Integration >', () => {
|
||||
{
|
||||
message: 'Did you mean to repeat this word?',
|
||||
range: createRange(2, 39, 2, 48),
|
||||
source: 'Harper (RepeatedWords)',
|
||||
source: 'Harper',
|
||||
code: 'RepeatedWords',
|
||||
},
|
||||
{
|
||||
message: 'Did you mean to spell `errorz` this way?',
|
||||
range: createRange(2, 26, 2, 32),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
},
|
||||
),
|
||||
);
|
||||
|
||||
@@ -57,7 +57,8 @@ describe('Languages >', () => {
|
||||
createExpectedDiagnostics({
|
||||
message: 'Did you mean to spell `Errorz` this way?',
|
||||
range: createRange(testCase.row, testCase.column, testCase.row, testCase.column + 6),
|
||||
source: 'Harper (SpellCheck)',
|
||||
source: 'Harper',
|
||||
code: 'SpellCheck',
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user