-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #750 from quantified-uncertainty/language-server
Language server; error location in SyntaxErrors
- Loading branch information
Showing
20 changed files
with
474 additions
and
1,442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/media/vendor | ||
/out | ||
/client/out | ||
/server/out | ||
/*.vsix | ||
/syntaxes/*.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as path from "path"; | ||
|
||
import * as vscode from "vscode"; | ||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
TransportKind, | ||
} from "vscode-languageclient/node"; | ||
|
||
let client: LanguageClient; | ||
|
||
export const startClient = (context: vscode.ExtensionContext) => { | ||
// The server is implemented in node | ||
let serverModule = context.asAbsolutePath( | ||
path.join("server", "out", "server.js") | ||
); | ||
// The debug options for the server | ||
// --inspect=6009: runs the server in Node's Inspector mode so VS Code can attach to the server for debugging | ||
let debugOptions = { execArgv: ["--nolazy" /*"--inspect=6009"*/] }; | ||
|
||
// If the extension is launched in debug mode then the debug server options are used | ||
// Otherwise the run options are used | ||
let serverOptions: ServerOptions = { | ||
run: { module: serverModule, transport: TransportKind.ipc }, | ||
debug: { | ||
module: serverModule, | ||
transport: TransportKind.ipc, | ||
options: debugOptions, | ||
}, | ||
}; | ||
|
||
// Options to control the language client | ||
let clientOptions: LanguageClientOptions = { | ||
// Register the server for plain text documents | ||
documentSelector: [{ scheme: "file", language: "squiggle" }], | ||
synchronize: { | ||
// Notify the server about file changes to '.clientrc files contained in the workspace | ||
fileEvents: vscode.workspace.createFileSystemWatcher("**/.clientrc"), | ||
}, | ||
}; | ||
|
||
// Create the language client and start the client. | ||
client = new LanguageClient( | ||
"squiggleServer", | ||
"Squiggle Server", | ||
serverOptions, | ||
clientOptions | ||
); | ||
|
||
// Start the client. This will also launch the server | ||
client.start(); | ||
}; | ||
|
||
export const stopClient = () => { | ||
if (!client) { | ||
return undefined; | ||
} | ||
return client.stop(); | ||
}; |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2020", | ||
"lib": ["ES2020", "dom"], | ||
"outDir": "out", | ||
"rootDir": "src", | ||
"sourceMap": true | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules", ".vscode-test"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { | ||
createConnection, | ||
TextDocuments, | ||
Diagnostic, | ||
DiagnosticSeverity, | ||
ProposedFeatures, | ||
InitializeParams, | ||
TextDocumentSyncKind, | ||
InitializeResult, | ||
} from "vscode-languageserver/node"; | ||
|
||
import { parse } from "@quri/squiggle-lang"; | ||
|
||
import { TextDocument } from "vscode-languageserver-textdocument"; | ||
|
||
// Create a connection for the server, using Node's IPC as a transport. | ||
// Also include all preview / proposed LSP features. | ||
let connection = createConnection(ProposedFeatures.all); | ||
|
||
const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument); | ||
|
||
documents.onDidChangeContent((change) => { | ||
validateSquiggleDocument(change.document); | ||
}); | ||
|
||
let hasDiagnosticRelatedInformationCapability = false; | ||
|
||
connection.onInitialize((params: InitializeParams) => { | ||
const capabilities = params.capabilities; | ||
|
||
hasDiagnosticRelatedInformationCapability = !!( | ||
capabilities.textDocument && | ||
capabilities.textDocument.publishDiagnostics && | ||
capabilities.textDocument.publishDiagnostics.relatedInformation | ||
); | ||
|
||
const result: InitializeResult = { | ||
capabilities: { | ||
textDocumentSync: TextDocumentSyncKind.Incremental, | ||
}, | ||
}; | ||
return result; | ||
}); | ||
|
||
async function validateSquiggleDocument( | ||
textDocument: TextDocument | ||
): Promise<void> { | ||
const text = textDocument.getText(); | ||
|
||
const diagnostics: Diagnostic[] = []; | ||
|
||
const parseResult = parse(text); | ||
if (parseResult.tag === "Error") { | ||
const location = parseResult.value.value[1]; | ||
diagnostics.push({ | ||
severity: DiagnosticSeverity.Error, | ||
range: { | ||
start: { | ||
line: location.start.line - 1, | ||
character: location.start.column - 1, | ||
}, | ||
end: { | ||
line: location.end.line - 1, | ||
character: location.end.column - 1, | ||
}, | ||
}, | ||
message: parseResult.value.value[0], | ||
}); | ||
} | ||
|
||
// Send the computed diagnostics to VSCode. | ||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics }); | ||
} | ||
|
||
// Make the text document manager listen on the connection | ||
// for open, change and close text document events | ||
documents.listen(connection); | ||
|
||
// Listen on the connection | ||
connection.listen(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"target": "es2020", | ||
"lib": ["ES2020", "dom"], | ||
"outDir": "out", | ||
"rootDir": "src", | ||
"sourceMap": true | ||
}, | ||
"include": ["src"], | ||
"exclude": ["node_modules"] | ||
} |
Oops, something went wrong.