Fix lints in diagnostics.ts
This commit is contained in:
parent
27f2b18ac1
commit
a570acf962
|
|
@ -1,5 +1,4 @@
|
|||
import type * as lsp from "vscode-languageserver-protocol"
|
||||
import {setDiagnostics} from "@codemirror/lint"
|
||||
import {ViewPlugin, ViewUpdate} from "@codemirror/view"
|
||||
import {LSPPlugin, LSPClientExtension} from "@codemirror/lsp-client"
|
||||
import {OpenFile} from "../filestate"
|
||||
|
|
@ -16,7 +15,7 @@ const autoSync = ViewPlugin.fromClass(class {
|
|||
if (this.pending != null) clearTimeout(this.pending)
|
||||
this.pending = setTimeout(() => {
|
||||
this.pending = null
|
||||
let plugin = LSPPlugin.get(update.view)
|
||||
const plugin = LSPPlugin.get(update.view)
|
||||
if (plugin) plugin.client.sync()
|
||||
}, 500)
|
||||
}
|
||||
|
|
@ -27,7 +26,7 @@ const autoSync = ViewPlugin.fromClass(class {
|
|||
})
|
||||
|
||||
function fromPosition(doc: Text, pos: lsp.Position): number {
|
||||
let line = doc.line(pos.line + 1)
|
||||
const line = doc.line(pos.line + 1)
|
||||
return line.from + pos.character
|
||||
}
|
||||
|
||||
|
|
@ -36,17 +35,15 @@ export function serverDiagnostics(): LSPClientExtension {
|
|||
clientCapabilities: {textDocument: {publishDiagnostics: {versionSupport: true}}},
|
||||
notificationHandlers: {
|
||||
"textDocument/publishDiagnostics": (client, params: lsp.PublishDiagnosticsParams) => {
|
||||
let file = client.workspace.getFile(params.uri) as OpenFile;
|
||||
const file = client.workspace.getFile(params.uri) as OpenFile;
|
||||
if (!file || params.version != null && params.version != file.version) return false;
|
||||
for(const view of file.editors.map(e => e.view)) {
|
||||
const mapPos = (p: number) => file.changes ? file.changes.mapPos(p) : p;
|
||||
file.setDiagnostics(params.diagnostics.map(item => ({
|
||||
from: mapPos(fromPosition(file.doc, item.range.start)),
|
||||
to: mapPos(fromPosition(file.doc, item.range.end)),
|
||||
severity: toSeverity(item.severity ?? 1),
|
||||
message: item.message,
|
||||
})));
|
||||
}
|
||||
const mapPos = (p: number) => file.changes ? file.changes.mapPos(p) : p;
|
||||
file.setDiagnostics(params.diagnostics.map(item => ({
|
||||
from: mapPos(fromPosition(file.doc, item.range.start)),
|
||||
to: mapPos(fromPosition(file.doc, item.range.end)),
|
||||
severity: toSeverity(item.severity ?? 1),
|
||||
message: item.message,
|
||||
})));
|
||||
return true
|
||||
}
|
||||
},
|
||||
|
|
|
|||
Loading…
Reference in New Issue