More work on the lsp
This commit is contained in:
71
parser.ts
71
parser.ts
@@ -388,11 +388,37 @@ function buildLineIndex(file: string) {
|
||||
}
|
||||
return lineIndex;
|
||||
}
|
||||
type Match = {
|
||||
message: string,
|
||||
shortMessage: string,
|
||||
offset: number,
|
||||
length: number,
|
||||
replacements: {
|
||||
value: string
|
||||
}[],
|
||||
context: {
|
||||
text: string,
|
||||
offset: number,
|
||||
length: number
|
||||
},
|
||||
sentence: string,
|
||||
rule: {
|
||||
id: string,
|
||||
subId: string,
|
||||
description: string,
|
||||
urls: {
|
||||
value: string
|
||||
}[],
|
||||
issueType: string,
|
||||
category: {
|
||||
id: string,
|
||||
name: string
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getDiagnostics(file: string): Promise<Dialog[]> {
|
||||
|
||||
const res = parseLsp(file);
|
||||
|
||||
export async function diagnosticsRequests(res: ParseResult): Promise < Match[] > {
|
||||
const formData = new URLSearchParams();
|
||||
|
||||
formData.set('text', res.text);
|
||||
@@ -414,40 +440,20 @@ export async function getDiagnostics(file: string): Promise<Dialog[]> {
|
||||
}
|
||||
const body = await rawRes.json();
|
||||
|
||||
type Match = {
|
||||
message: string,
|
||||
shortMessage: string,
|
||||
offset: number,
|
||||
length: number,
|
||||
replacements: {
|
||||
value: string
|
||||
}[],
|
||||
context: {
|
||||
text: string,
|
||||
offset: number,
|
||||
length: number
|
||||
},
|
||||
sentence: string,
|
||||
rule: {
|
||||
id: string,
|
||||
subId: string,
|
||||
description: string,
|
||||
urls: {
|
||||
value: string
|
||||
}[],
|
||||
issueType: string,
|
||||
category: {
|
||||
id: string,
|
||||
name: string
|
||||
}
|
||||
}
|
||||
}
|
||||
return body.matches;
|
||||
}
|
||||
|
||||
export async function getDiagnostics(file: string): Promise<(Dialog & {replacements: string[]})[]> {
|
||||
|
||||
const res = parseLsp(file);
|
||||
|
||||
const matches = await diagnosticsRequests(res);
|
||||
|
||||
const lineIndex = buildLineIndex(file);
|
||||
|
||||
const diags = [];
|
||||
|
||||
for (const i of body.matches) {
|
||||
for (const i of matches) {
|
||||
const match: Match = i;
|
||||
const original_position = getOriginalPostion(res, match.offset);
|
||||
if (original_position == -1) {
|
||||
@@ -466,6 +472,7 @@ export async function getDiagnostics(file: string): Promise<Dialog[]> {
|
||||
range,
|
||||
severity: Severity.Error,
|
||||
message: match.message,
|
||||
replacements: match.replacements.map(a => a.value),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user