-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
245 additions
and
27 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,2 +1,3 @@ | ||
export { parse } from "./compiler/parser.js"; | ||
export { assemble } from "./compiler/assembler.js"; | ||
export { assemble } from "./compiler/assembler.js"; | ||
export { analyze } from "./compiler/analyzer.js"; |
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,36 +1,83 @@ | ||
import { | ||
createConnection, TextDocuments, ProposedFeatures, TextDocumentSyncKind | ||
createConnection, TextDocuments, TextDocumentSyncKind, Diagnostic, DiagnosticSeverity, CompletionItem, CompletionItemKind | ||
} from "vscode-languageserver/node"; | ||
|
||
import { | ||
TextDocument | ||
} from "vscode-languageserver-textdocument"; | ||
|
||
import { analyze } from "@ramattra/ramattra-core"; | ||
|
||
// Creates the LSP connection | ||
const connection = createConnection(ProposedFeatures.all); | ||
const connection = createConnection(); | ||
const documents = new TextDocuments(TextDocument); | ||
|
||
// Create a manager for open text documents | ||
const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument); | ||
documents.onDidOpen((event) => { | ||
connection.console.log(`[Server(${process.pid})] Document opened: ${event.document.uri}`); | ||
}); | ||
|
||
// The workspace folder this server is operating on | ||
let workspaceFolder: string | null; | ||
connection.onCompletion((_pos): CompletionItem[] => { | ||
return [ | ||
{ | ||
label: "TestingCompletion", | ||
kind: CompletionItemKind.Text, | ||
data: 1 | ||
} | ||
]; | ||
}); | ||
|
||
documents.onDidOpen((event) => { | ||
connection.console.log(`[Server(${process.pid}) ${workspaceFolder}] Document opened: ${event.document.uri}`); | ||
connection.onCompletionResolve( | ||
(item): CompletionItem => { | ||
if (item.data == 1) { | ||
item.detail = "TypeScript details"; | ||
item.documentation = "TypeScript documentation"; | ||
} | ||
|
||
return item; | ||
} | ||
); | ||
|
||
async function validateDocument(document: TextDocument) { | ||
const text = document.getText(); | ||
|
||
const diagnostics: Diagnostic[] = []; | ||
|
||
try { | ||
analyze(text); | ||
} catch (err) { | ||
diagnostics.push({ | ||
severity: DiagnosticSeverity.Error, | ||
range: { | ||
start: document.positionAt(0), | ||
end: document.positionAt(0) | ||
}, | ||
message: `${err}`, | ||
source: "Ramattra Language Server" | ||
}); | ||
} | ||
|
||
await connection.sendDiagnostics({ uri: document.uri, diagnostics }) | ||
} | ||
|
||
documents.onDidChangeContent(async e => { | ||
await validateDocument(e.document); | ||
}); | ||
|
||
documents.listen(connection); | ||
|
||
connection.onInitialize((params) => { | ||
workspaceFolder = params.rootUri; | ||
connection.console.log(`[Server(${process.pid}) ${workspaceFolder}] Started and initialize received`); | ||
connection.onInitialize((_params) => { | ||
connection.console.log(`[Server(${process.pid})] Started and initialize received`); | ||
|
||
return { | ||
capabilities: { | ||
textDocumentSync: { | ||
openClose: true, | ||
change: TextDocumentSyncKind.None | ||
change: TextDocumentSyncKind.Incremental | ||
}, | ||
completionProvider: { | ||
resolveProvider: true | ||
} | ||
} | ||
}; | ||
}); | ||
connection.listen(); | ||
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,20 @@ | ||
{ | ||
"version": "0.2.0", | ||
// List of configurations. Add new configurations or edit existing ones. | ||
"configurations": [ | ||
{ | ||
"type": "extensionHost", | ||
"request": "launch", | ||
"name": "Launch Client", | ||
"runtimeExecutable": "${execPath}", | ||
"args": [ | ||
"--extensionDevelopmentPath=${workspaceRoot}" | ||
], | ||
"autoAttachChildProcesses": true, | ||
"sourceMaps": true, | ||
"outFiles": [ | ||
"${workspaceRoot}/dist/**/*.js" | ||
] | ||
} | ||
] | ||
} |
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* -------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
* ------------------------------------------------------------------------------------------ */ | ||
|
||
import * as path from "path"; | ||
import { workspace, ExtensionContext } from "vscode"; | ||
|
||
import { | ||
LanguageClient, | ||
LanguageClientOptions, | ||
ServerOptions, | ||
TransportKind | ||
} from "vscode-languageclient/node"; | ||
|
||
let client: LanguageClient; | ||
|
||
export function activate(context: ExtensionContext) { | ||
// The server is implemented in node | ||
const serverModule = context.asAbsolutePath( | ||
path.join("..", "ramattra-language-server", "dist", "server.js") | ||
); | ||
|
||
// If the extension is launched in debug mode then the debug server options are used | ||
// Otherwise the run options are used | ||
const serverOptions: ServerOptions = { | ||
run: { module: serverModule, transport: TransportKind.ipc }, | ||
debug: { | ||
module: serverModule, | ||
transport: TransportKind.ipc, | ||
} | ||
}; | ||
|
||
// Options to control the language client | ||
const clientOptions: LanguageClientOptions = { | ||
documentSelector: [{ scheme: "file", language: "ramattra" }], | ||
synchronize: { | ||
// Notify the server about file changes to ".clientrc files contained in the workspace | ||
fileEvents: workspace.createFileSystemWatcher("**/.clientrc") | ||
} | ||
}; | ||
|
||
// Create the language client and start the client. | ||
client = new LanguageClient( | ||
"ramattra-language-server", | ||
"Ramattra Language Server", | ||
serverOptions, | ||
clientOptions | ||
); | ||
|
||
// Start the client. This will also launch the server | ||
client.start(); | ||
} | ||
|
||
export function deactivate(): Thenable<void> | undefined { | ||
if (!client) { | ||
return undefined; | ||
} | ||
return client.stop(); | ||
} |
Oops, something went wrong.