-
-
Notifications
You must be signed in to change notification settings - Fork 4
Modified the language server so it sends the results of the interpreter #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
555ae8b
updated langium version, modified lanuage server
f5ddda0
added a timeout and error handling to the lsp
755a267
changed the timeout time
b8e5b5f
small fix
e540702
small fix
2cc5f0d
fixed small stuff
7ca66b8
added an error when classes get created
f335a06
added unsupported classes to validation
ddd0ee2
validation
4a928d6
added a cancellationToken to the interpreter
a5396ab
improved timeout (still doesn't work)
7fad26c
addeded a trhow
a643beb
timeout works now, yay
4c81da4
refactored timeout
93b88cb
increased timeout time
7ddaff1
fixed timeout
bfd6a07
removed weird console.log
687b17c
improved coding style
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 hidden or 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,51 @@ | ||
| /****************************************************************************** | ||
| * Copyright 2022 TypeFox GmbH | ||
| * This program and the accompanying materials are made available under the | ||
| * terms of the MIT License, which is available in the project root. | ||
| ******************************************************************************/ | ||
|
|
||
| import { startLanguageServer, EmptyFileSystem, DocumentState, LangiumDocument } from 'langium'; | ||
| import { BrowserMessageReader, BrowserMessageWriter, Diagnostic, NotificationType, createConnection } from 'vscode-languageserver/browser'; | ||
| import { createLoxServices } from './lox-module'; | ||
| import { runInterpreter } from '../interpreter/runner'; | ||
|
|
||
| declare const self: DedicatedWorkerGlobalScope; | ||
|
|
||
| /* browser specific setup code */ | ||
| const messageReader = new BrowserMessageReader(self); | ||
| const messageWriter = new BrowserMessageWriter(self); | ||
|
|
||
| const connection = createConnection(messageReader, messageWriter); | ||
|
|
||
| // Inject the shared services and language-specific services | ||
| const { shared } = createLoxServices({ connection, ...EmptyFileSystem }); | ||
|
|
||
| // Start the language server with the shared services | ||
| startLanguageServer(shared); | ||
|
|
||
| // Send a notification with the serialized AST after every document change | ||
| type DocumentChange = { uri: string, content: string, diagnostics: Diagnostic[] }; | ||
| const documentChangeNotification = new NotificationType<DocumentChange>('browser/DocumentChange'); | ||
| shared.workspace.DocumentBuilder.onBuildPhase(DocumentState.Validated, documents => { | ||
| for (const document of documents) { | ||
| if (document.diagnostics === undefined || document.diagnostics.filter((i) => i.severity === 1).length === 0) { | ||
| sendMessage(document, "notification", "startInterpreter") | ||
| runInterpreter(document.textDocument.getText(), { | ||
emilkrebs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
emilkrebs marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| log: (message) => { | ||
| sendMessage(document, "output", message) | ||
| } | ||
| }) | ||
| } | ||
| else { | ||
| sendMessage(document, "error", document.diagnostics) | ||
| } | ||
| } | ||
| }); | ||
|
|
||
| function sendMessage(document: LangiumDocument, type: string, content: unknown): void { | ||
| connection.sendNotification(documentChangeNotification, { | ||
| uri: document.uri.toString(), | ||
| content: JSON.stringify({ type, content }), | ||
| diagnostics: document.diagnostics ?? [] | ||
| }); | ||
| } | ||
This file contains hidden or 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,30 @@ | ||
| // Monarch syntax highlighting for the lox language. | ||
| export default { | ||
| keywords: [ | ||
| 'and','boolean','class','else','false','for','fun','if','nil','number','or','print','return','string','super','this','true','var','void','while' | ||
| ], | ||
| operators: [ | ||
| '!','!=','*','+',',','-','.','/',':',';','<','<=','=','==','=>','>','>=' | ||
| ], | ||
| symbols: /!|!=|\(|\)|\*|\+|,|-|\.|/|:|;|<|<=|=|==|=>|>|>=|\{|\}/, | ||
|
|
||
| tokenizer: { | ||
| initial: [ | ||
| { regex: /[_a-zA-Z][\w_]*/, action: { cases: { '@keywords': {"token":"keyword"}, '@default': {"token":"ID"} }} }, | ||
| { regex: /[0-9]+(\.[0-9]+)?/, action: {"token":"number"} }, | ||
| { regex: /"[^"]*"/, action: {"token":"string"} }, | ||
| { include: '@whitespace' }, | ||
| { regex: /@symbols/, action: { cases: { '@operators': {"token":"operator"}, '@default': {"token":""} }} }, | ||
| ], | ||
| whitespace: [ | ||
| { regex: /\s+/, action: {"token":"white"} }, | ||
| { regex: /\/\*/, action: {"token":"comment","next":"@comment"} }, | ||
| { regex: /\/\/[^\n\r]*/, action: {"token":"comment"} }, | ||
| ], | ||
| comment: [ | ||
| { regex: /[^\/\*]+/, action: {"token":"comment"} }, | ||
| { regex: /\*\//, action: {"token":"comment","next":"@pop"} }, | ||
| { regex: /[\/\*]/, action: {"token":"comment"} }, | ||
| ], | ||
| } | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.