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 type * as lsp from "vscode-languageserver-protocol"
|
||||||
import {setDiagnostics} from "@codemirror/lint"
|
|
||||||
import {ViewPlugin, ViewUpdate} from "@codemirror/view"
|
import {ViewPlugin, ViewUpdate} from "@codemirror/view"
|
||||||
import {LSPPlugin, LSPClientExtension} from "@codemirror/lsp-client"
|
import {LSPPlugin, LSPClientExtension} from "@codemirror/lsp-client"
|
||||||
import {OpenFile} from "../filestate"
|
import {OpenFile} from "../filestate"
|
||||||
|
|
@ -16,7 +15,7 @@ const autoSync = ViewPlugin.fromClass(class {
|
||||||
if (this.pending != null) clearTimeout(this.pending)
|
if (this.pending != null) clearTimeout(this.pending)
|
||||||
this.pending = setTimeout(() => {
|
this.pending = setTimeout(() => {
|
||||||
this.pending = null
|
this.pending = null
|
||||||
let plugin = LSPPlugin.get(update.view)
|
const plugin = LSPPlugin.get(update.view)
|
||||||
if (plugin) plugin.client.sync()
|
if (plugin) plugin.client.sync()
|
||||||
}, 500)
|
}, 500)
|
||||||
}
|
}
|
||||||
|
|
@ -27,7 +26,7 @@ const autoSync = ViewPlugin.fromClass(class {
|
||||||
})
|
})
|
||||||
|
|
||||||
function fromPosition(doc: Text, pos: lsp.Position): number {
|
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
|
return line.from + pos.character
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -36,9 +35,8 @@ export function serverDiagnostics(): LSPClientExtension {
|
||||||
clientCapabilities: {textDocument: {publishDiagnostics: {versionSupport: true}}},
|
clientCapabilities: {textDocument: {publishDiagnostics: {versionSupport: true}}},
|
||||||
notificationHandlers: {
|
notificationHandlers: {
|
||||||
"textDocument/publishDiagnostics": (client, params: lsp.PublishDiagnosticsParams) => {
|
"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;
|
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;
|
const mapPos = (p: number) => file.changes ? file.changes.mapPos(p) : p;
|
||||||
file.setDiagnostics(params.diagnostics.map(item => ({
|
file.setDiagnostics(params.diagnostics.map(item => ({
|
||||||
from: mapPos(fromPosition(file.doc, item.range.start)),
|
from: mapPos(fromPosition(file.doc, item.range.start)),
|
||||||
|
|
@ -46,7 +44,6 @@ export function serverDiagnostics(): LSPClientExtension {
|
||||||
severity: toSeverity(item.severity ?? 1),
|
severity: toSeverity(item.severity ?? 1),
|
||||||
message: item.message,
|
message: item.message,
|
||||||
})));
|
})));
|
||||||
}
|
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue