mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-19 17:26:13 +00:00
53 lines
No EOL
1.7 KiB
TypeScript
53 lines
No EOL
1.7 KiB
TypeScript
import * as vsclang from 'vscode-languageserver'
|
|
import * as vsclangproto from 'vscode-languageserver-protocol'
|
|
import { completions } from './completionProvider'
|
|
import { preprocess, ext, formatURI } from './linter'
|
|
import { extname } from 'path'
|
|
|
|
export let connection: vsclang.IConnection
|
|
connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process))
|
|
|
|
import { onConfigChange } from './config'
|
|
|
|
export const documents = new vsclang.TextDocuments()
|
|
documents.listen(connection)
|
|
|
|
connection.onInitialize((params): vsclang.InitializeResult => (
|
|
{
|
|
capabilities: {
|
|
textDocumentSync: documents.syncKind,
|
|
completionProvider: {
|
|
resolveProvider: true
|
|
},
|
|
}
|
|
}
|
|
))
|
|
|
|
connection.onExit(() => {})
|
|
|
|
documents.onDidOpen((event) => onEvent(event.document))
|
|
|
|
documents.onDidSave((event) => onEvent(event.document))
|
|
|
|
// dont do this for include files, for non-include files, clear diags for all its includes. Cache this maybe
|
|
documents.onDidClose((event) => connection.sendDiagnostics({uri: event.document.uri, diagnostics: []}))
|
|
|
|
//documents.onDidChangeContent(onEvent)
|
|
|
|
export function onEvent(document: vsclangproto.TextDocument) {
|
|
if (!ext.has(extname(document.uri))) return
|
|
try {
|
|
preprocess(document.getText().split('\n'), formatURI(document.uri))
|
|
} catch (e) {
|
|
connection.window.showErrorMessage(`[mc-glsl] ${e.message}`)
|
|
throw(e)
|
|
}
|
|
}
|
|
|
|
connection.onDidChangeConfiguration(onConfigChange)
|
|
|
|
connection.onCompletion((textDocumentPosition: vsclang.TextDocumentPositionParams) => completions)
|
|
|
|
connection.onCompletionResolve((item: vsclang.CompletionItem): vsclang.CompletionItem => completions[item.data - 1])
|
|
|
|
connection.listen() |