mirror of
https://github.com/Strum355/mcshader-lsp.git
synced 2025-07-24 11:44:44 +00:00
Added config to server
This commit is contained in:
parent
47634290aa
commit
63151eaa76
9 changed files with 196 additions and 266 deletions
13
server/src/config.ts
Normal file
13
server/src/config.ts
Normal file
|
@ -0,0 +1,13 @@
|
|||
export class Config {
|
||||
public readonly minecraftPath: string
|
||||
public readonly glslangPath: string
|
||||
|
||||
constructor(mcPath: string, glslangPath: string) {
|
||||
this.minecraftPath = mcPath
|
||||
this.glslangPath = glslangPath
|
||||
}
|
||||
|
||||
public onChange(c: Config) {
|
||||
Object.assign(this, c)
|
||||
}
|
||||
}
|
|
@ -1,59 +1,61 @@
|
|||
import { IPCMessageReader, IPCMessageWriter, createConnection, IConnection,
|
||||
TextDocuments, TextDocument, Diagnostic, DiagnosticSeverity, InitializeResult, TextDocumentPositionParams, CompletionItem, CompletionItemKind
|
||||
} from 'vscode-languageserver';
|
||||
import * as vsclang from 'vscode-languageserver'
|
||||
import { Config } from './config'
|
||||
|
||||
// Create a connection for the server. The connection uses Node's IPC as a transport
|
||||
const connection: IConnection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));
|
||||
const connection = vsclang.createConnection(new vsclang.IPCMessageReader(process), new vsclang.IPCMessageWriter(process));
|
||||
|
||||
const documents = new vsclang.TextDocuments();
|
||||
|
||||
// Create a simple text document manager. The text document manager
|
||||
// supports full document sync only
|
||||
const documents: TextDocuments = new TextDocuments();
|
||||
// Make the text document manager listen on the connection
|
||||
// for open, change and close text document events
|
||||
documents.listen(connection);
|
||||
|
||||
// After the server has started, the client sends an initialize request. The server receives
|
||||
// in the passed params, the rootPath of the workspace plus the client capabilities.
|
||||
connection.onInitialize((params): InitializeResult => {
|
||||
const conf = new Config('', '')
|
||||
|
||||
connection.onInitialize((params): vsclang.InitializeResult => {
|
||||
return {
|
||||
capabilities: {
|
||||
// Tell the client that the server works in FULL text document sync mode
|
||||
textDocumentSync: documents.syncKind,
|
||||
// Tell the client that the server supports code completion
|
||||
textDocumentSync: vsclang.TextDocumentSyncKind.Incremental,
|
||||
completionProvider: {
|
||||
resolveProvider: true
|
||||
}
|
||||
},
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
// The content of a text document has changed. This event is emitted
|
||||
// when the text document is first opened or when its content has changed.
|
||||
documents.onDidChangeContent((change) => {
|
||||
validateTextDocument(change.document);
|
||||
});
|
||||
|
||||
// The settings have changed. It is sent on server activation
|
||||
// as well.
|
||||
connection.onDidChangeConfiguration((change) => {
|
||||
conf.onChange(change.settings as Config)
|
||||
documents.all().forEach(validateTextDocument);
|
||||
});
|
||||
|
||||
function validateTextDocument(textDocument: TextDocument): void {
|
||||
const diagnostics: Diagnostic[] = [];
|
||||
connection.onDidChangeTextDocument((param) => {
|
||||
console.log(param.contentChanges)
|
||||
})
|
||||
|
||||
connection.onDidOpenTextDocument((param) => {
|
||||
console.log(param)
|
||||
})
|
||||
|
||||
connection.onDidCloseTextDocument((param) => {
|
||||
console.log(param)
|
||||
})
|
||||
|
||||
function validateTextDocument(textDocument: vsclang.TextDocument) {
|
||||
const diagnostics: vsclang.Diagnostic[] = [];
|
||||
const lines = textDocument.getText().split(/\r?\n/g);
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
const line = lines[i];
|
||||
const index = line.indexOf('typescript');
|
||||
if (index >= 0) {
|
||||
diagnostics.push({
|
||||
severity: DiagnosticSeverity.Warning,
|
||||
severity: vsclang.DiagnosticSeverity.Warning,
|
||||
range: {
|
||||
start: { line: i, character: index },
|
||||
end: { line: i, character: index + 10 }
|
||||
},
|
||||
message: `${line.substr(index, 10)} should be spelled TypeScript`,
|
||||
source: 'ex'
|
||||
message: `blah blah Todd Howard`,
|
||||
source: 'mcglsl'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -61,62 +63,28 @@ function validateTextDocument(textDocument: TextDocument): void {
|
|||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
||||
}
|
||||
|
||||
connection.onDidChangeWatchedFiles((change) => {
|
||||
// Monitored files have changed in VS Code
|
||||
connection.console.log('We received a file change event');
|
||||
});
|
||||
|
||||
// This handler provides the initial list of the completion items.
|
||||
connection.onCompletion((textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
|
||||
// The passed parameter contains the position in the text document in
|
||||
// which code completion was requested. For this example, we ignore this
|
||||
// information and always provide the same completion items.
|
||||
connection.onCompletion((textDocumentPosition: vsclang.TextDocumentPositionParams): vsclang.CompletionItem[] => {
|
||||
return [
|
||||
{
|
||||
label: 'TypeScript',
|
||||
kind: CompletionItemKind.Text,
|
||||
label: 'heldItemId',
|
||||
kind: vsclang.CompletionItemKind.Variable,
|
||||
data: 0,
|
||||
},{
|
||||
label: 'hot',
|
||||
kind: vsclang.CompletionItemKind.Property,
|
||||
data: 1
|
||||
},
|
||||
{
|
||||
label: 'JavaScript',
|
||||
kind: CompletionItemKind.Text,
|
||||
data: 2
|
||||
}
|
||||
];
|
||||
}];
|
||||
});
|
||||
|
||||
// This handler resolves additional information for the item selected in
|
||||
// the completion list.
|
||||
connection.onCompletionResolve((item: CompletionItem): CompletionItem => {
|
||||
if (item.data === 1) {
|
||||
item.detail = 'TypeScript details',
|
||||
item.documentation = 'TypeScript documentation'
|
||||
} else if (item.data === 2) {
|
||||
item.detail = 'JavaScript details',
|
||||
item.documentation = 'JavaScript documentation'
|
||||
connection.onCompletionResolve((item: vsclang.CompletionItem): vsclang.CompletionItem => {
|
||||
if (item.data === 0) {
|
||||
item.documentation = 'blyat man'
|
||||
item.detail = 'Held item ID (main hand)'
|
||||
} else if (item.data === 1) {
|
||||
item.documentation = 'random'
|
||||
item.detail = 'something'
|
||||
}
|
||||
return item;
|
||||
return item
|
||||
});
|
||||
|
||||
/*
|
||||
connection.onDidOpenTextDocument((params) => {
|
||||
// A text document was opened in VS Code.
|
||||
// params.uri uniquely identifies the document. For documents stored on disk, this is a file URI.
|
||||
// params.text the initial full content of the document.
|
||||
connection.console.log(`${params.textDocument.uri} opened.`);
|
||||
});
|
||||
connection.onDidChangeTextDocument((params) => {
|
||||
// The content of a text document has changed in VS Code.
|
||||
// params.uri uniquely identifies the document.
|
||||
// params.contentChanges describe the content changes to the document.
|
||||
connection.console.log(`${params.textDocument.uri} changed: ${JSON.stringify(params.contentChanges)}`);
|
||||
});
|
||||
connection.onDidCloseTextDocument((params) => {
|
||||
// A text document was closed in VS Code.
|
||||
// params.uri uniquely identifies the document.
|
||||
connection.console.log(`${params.textDocument.uri} closed.`);
|
||||
});
|
||||
*/
|
||||
|
||||
// Listen on the connection
|
||||
connection.listen();
|
Loading…
Add table
Add a link
Reference in a new issue