diff --git a/client/src/BranFlakesExecutorVisitor.ts b/client/src/BranFlakesExecutorVisitor.ts index 41bb667..5c6bd9d 100644 --- a/client/src/BranFlakesExecutorVisitor.ts +++ b/client/src/BranFlakesExecutorVisitor.ts @@ -4,9 +4,9 @@ import { bfVisitor } from './generated/bfVisitor'; import { DiagnosticSeverity } from 'vscode-languageclient'; import { getTree } from './BranFlakesParseRunner'; import { RuleNode } from 'antlr4ts/tree/RuleNode'; -import InputStrategy from './input/InputStrategy'; +import type InputStrategy from './input/InputStrategy'; -export default class BranFlakesExecutorVisitor +export class BranFlakesExecutorVisitor extends AbstractParseTreeVisitor> implements bfVisitor> { diff --git a/client/src/command/BranFlakesCommand.ts b/client/src/command/BranFlakesCommand.ts new file mode 100644 index 0000000..96ca577 --- /dev/null +++ b/client/src/command/BranFlakesCommand.ts @@ -0,0 +1,4 @@ +export interface BranFlakesCommand { + getCommandName(): string; + getCommandHandler(): (...args: any) => Promise; +} diff --git a/client/src/command/Command.ts b/client/src/command/Command.ts deleted file mode 100644 index da04d5d..0000000 --- a/client/src/command/Command.ts +++ /dev/null @@ -1,5 +0,0 @@ - -export interface Command{ - getCommandName():string; - getCommandHandler():(...args:any)=>Promise; -} \ No newline at end of file diff --git a/client/src/command/CompileCommand.ts b/client/src/command/CompileBranFlakesCommand.ts similarity index 81% rename from client/src/command/CompileCommand.ts rename to client/src/command/CompileBranFlakesCommand.ts index d639080..23fd32e 100644 --- a/client/src/command/CompileCommand.ts +++ b/client/src/command/CompileBranFlakesCommand.ts @@ -1,7 +1,6 @@ import { window } from 'vscode'; -import { Command as BranFlakesCommand } from './Command'; +import type { BranFlakesCommand } from './BranFlakesCommand'; import { VSCodePromptInputStrategy } from '../input/VSCodePromptInputStrategy'; -import BranFlakesExecutorVisitor from '../BranFlakesExecutorVisitor'; export class CompileBranFlakesCommand implements BranFlakesCommand { getCommandName() { @@ -14,6 +13,10 @@ export class CompileBranFlakesCommand implements BranFlakesCommand { const inputStrategy = new VSCodePromptInputStrategy( window.showInputBox ); + const { BranFlakesExecutorVisitor } = await import( + '../BranFlakesExecutorVisitor' + ); + const output = await BranFlakesExecutorVisitor.run( text, fn, diff --git a/client/src/extension.ts b/client/src/extension.ts index b1e4edb..fa23400 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -4,14 +4,15 @@ * ------------------------------------------------------------------------------------------ */ import * as path from 'path'; -import { ExtensionContext, commands, window } from 'vscode'; +import { commands } from 'vscode'; +import type { ExtensionContext } from 'vscode'; import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, } from 'vscode-languageclient'; -import { CompileBranFlakesCommand } from './command/CompileCommand'; +import { CompileBranFlakesCommand } from './command/CompileBranFlakesCommand'; let client: LanguageClient; diff --git a/client/src/input/VSCodePromptInputStrategy.ts b/client/src/input/VSCodePromptInputStrategy.ts index cec77c2..dd2423e 100644 --- a/client/src/input/VSCodePromptInputStrategy.ts +++ b/client/src/input/VSCodePromptInputStrategy.ts @@ -1,5 +1,5 @@ -import { CancellationToken, InputBoxOptions } from 'vscode'; -import InputStrategy from './InputStrategy'; +import type { CancellationToken, InputBoxOptions } from 'vscode'; +import type InputStrategy from './InputStrategy'; export class VSCodePromptInputStrategy implements InputStrategy { private inputQueue: string = ''; diff --git a/package.json b/package.json index 449743f..05f77f4 100644 --- a/package.json +++ b/package.json @@ -5,9 +5,9 @@ "author": "Atreya Bain", "license": "MIT", "publisher": "atreyabain", - "version": "0.2.0", + "version": "0.2.1", "icon": "assets/128.png", - "categories": [], + "categories": ["Programming Languages","Linters"], "keywords": [ "multi-root ready", "brainfuck", diff --git a/server/src/server.ts b/server/src/server.ts index 37598db..cb1b687 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -3,31 +3,26 @@ * Licensed under the MIT License. See License.txt in the project root for license information. * ------------------------------------------------------------------------------------------ */ import { - createConnection, - TextDocuments, - Diagnostic, - DiagnosticSeverity, - ProposedFeatures, - InitializeParams, - DidChangeConfigurationNotification, - CompletionItem, - CompletionItemKind, - TextDocumentPositionParams, - TextDocumentSyncKind, - InitializeResult, - Position, + createConnection, + TextDocuments, + Diagnostic, + DiagnosticSeverity, + ProposedFeatures, + InitializeParams, + DidChangeConfigurationNotification, + CompletionItem, + CompletionItemKind, + TextDocumentPositionParams, + TextDocumentSyncKind, + InitializeResult, } from 'vscode-languageserver'; - - import { TextDocument } from 'vscode-languageserver-textdocument'; - // Create a connection for the server. The connection uses Node's IPC as a transport. // Also include all preview / proposed LSP features. let connection = createConnection(ProposedFeatures.all); - // Create a simple text document manager. The text document manager // supports full document sync only let documents: TextDocuments = new TextDocuments(TextDocument); @@ -37,60 +32,60 @@ let hasWorkspaceFolderCapability: boolean = false; let hasDiagnosticRelatedInformationCapability: boolean = false; connection.onInitialize((params: InitializeParams) => { - let capabilities = params.capabilities; + let capabilities = params.capabilities; - // Does the client support the `workspace/configuration` request? - // If not, we will fall back using global settings - hasConfigurationCapability = !!( - capabilities.workspace && !!capabilities.workspace.configuration - ); - hasWorkspaceFolderCapability = !!( - capabilities.workspace && !!capabilities.workspace.workspaceFolders - ); - hasDiagnosticRelatedInformationCapability = !!( - capabilities.textDocument && - capabilities.textDocument.publishDiagnostics && - capabilities.textDocument.publishDiagnostics.relatedInformation - ); + // Does the client support the `workspace/configuration` request? + // If not, we will fall back using global settings + hasConfigurationCapability = !!( + capabilities.workspace && !!capabilities.workspace.configuration + ); + hasWorkspaceFolderCapability = !!( + capabilities.workspace && !!capabilities.workspace.workspaceFolders + ); + hasDiagnosticRelatedInformationCapability = !!( + capabilities.textDocument && + capabilities.textDocument.publishDiagnostics && + capabilities.textDocument.publishDiagnostics.relatedInformation + ); - const result: InitializeResult = { - capabilities: { - textDocumentSync: TextDocumentSyncKind.Incremental, - // Tell the client that the server supports code completion - completionProvider: { - resolveProvider: false, - triggerCharacters: ['.'], - }, - }, - }; - if (hasWorkspaceFolderCapability) { - result.capabilities.workspace = { - workspaceFolders: { - supported: true, - }, - }; - } - return result; + const result: InitializeResult = { + capabilities: { + textDocumentSync: TextDocumentSyncKind.Incremental, + // Tell the client that the server supports code completion + completionProvider: { + resolveProvider: false, + triggerCharacters: ['.'], + }, + }, + }; + if (hasWorkspaceFolderCapability) { + result.capabilities.workspace = { + workspaceFolders: { + supported: true, + }, + }; + } + return result; }); connection.onInitialized(() => { - if (hasConfigurationCapability) { - // Register for all configuration changes. - connection.client.register( - DidChangeConfigurationNotification.type, - undefined - ); - } - if (hasWorkspaceFolderCapability) { - connection.workspace.onDidChangeWorkspaceFolders(_event => { - connection.console.log('Workspace folder change event received.'); - }); - } + if (hasConfigurationCapability) { + // Register for all configuration changes. + connection.client.register( + DidChangeConfigurationNotification.type, + undefined + ); + } + if (hasWorkspaceFolderCapability) { + connection.workspace.onDidChangeWorkspaceFolders(_event => { + connection.console.log('Workspace folder change event received.'); + }); + } }); // The example settings interface ExampleSettings { - maxNumberOfProblems: number; + maxNumberOfProblems: number; } // The global settings, used when the `workspace/configuration` request is not supported by the client. @@ -103,154 +98,142 @@ let globalSettings: ExampleSettings = defaultSettings; let documentSettings: Map> = new Map(); connection.onDidChangeConfiguration(change => { - if (hasConfigurationCapability) { - // Reset all cached document settings - documentSettings.clear(); - } else { - globalSettings = ( - (change.settings.languageServerExample || defaultSettings) - ); - } + if (hasConfigurationCapability) { + // Reset all cached document settings + documentSettings.clear(); + } else { + globalSettings = ( + (change.settings.languageServerExample || defaultSettings) + ); + } - // Revalidate all open text documents - documents.all().forEach(validateTextDocument); + // Revalidate all open text documents + Promise.all(documents.all().map(validateTextDocument)).catch(e => { + connection.console.log('Failed to validate text documents'); + }); }); function getDocumentSettings(resource: string): Thenable { - if (!hasConfigurationCapability) { - return Promise.resolve(globalSettings); - } - let result = documentSettings.get(resource); - if (!result) { - result = connection.workspace.getConfiguration({ - scopeUri: resource, - section: 'languageServerExample', - }); - documentSettings.set(resource, result); - } - return result; + if (!hasConfigurationCapability) { + return Promise.resolve(globalSettings); + } + let result = documentSettings.get(resource); + if (!result) { + result = connection.workspace.getConfiguration({ + scopeUri: resource, + section: 'languageServerExample', + }); + documentSettings.set(resource, result); + } + return result; } // Only keep settings for open documents documents.onDidClose(e => { - documentSettings.delete(e.document.uri); + documentSettings.delete(e.document.uri); }); // The content of a text document has changed. This event is emitted // when the text document first opened or when its content has changed. documents.onDidChangeContent(change => { - //change.contentChanges; - validateTextDocument(change.document); + validateTextDocument(change.document); }); //Run when saved documents.onDidSave(change => { - validateTextDocument(change.document); + validateTextDocument(change.document); }); const validateBrackets = (text: string) => { - let count = 0, lp: number[] = [],issues:number[]=[]; - const textsplit = text.split(''); - textsplit.forEach((x, i) => { - if (x === '[' || x === ']') { - - if (x === '[') {lp.push(i);} - if (x === ']') {if(lp.length===0) {issues.push(i);}lp.pop();} + let count = 0, + lp: number[] = [], + issues: number[] = []; + const textsplit = text.split(''); + textsplit.forEach((x, i) => { + if (x === '[' || x === ']') { + if (x === '[') { + lp.push(i); + } + if (x === ']') { + if (lp.length === 0) { + issues.push(i); + } + lp.pop(); + } + } + }); - - } - - }); - - return [...lp,...issues]; + return [...lp, ...issues]; }; async function validateTextDocument(textDocument: TextDocument): Promise { - // In this simple example we get the settings for every validate run. - let settings = await getDocumentSettings(textDocument.uri); - // The validator creates diagnostics for all uppercase words length 2 and more - const text = textDocument.getText(); + // In this simple example we get the settings for every validate run. + let settings = await getDocumentSettings(textDocument.uri); + // The validator creates diagnostics for all uppercase words length 2 and more + const text = textDocument.getText(); - let problems = 0; - let diagnostics: Diagnostic[] = []; - const issues = validateBrackets(text); - - diagnostics.push(...issues.map(e => ({ - message: 'Brackets unmatched', - range:{ - start: textDocument.positionAt(e), - end: textDocument.positionAt(e+1), - }, - severity:DiagnosticSeverity.Error, - code:'[ and ]', - }))); - - // diagnostics.push({ - // message: 'Brackets not matched', - // range: { - // start: { line: 0, character: 0 }, - // end: { line: 0, character: 0 }, - // }, - // }); + let problems = 0; + let diagnostics: Diagnostic[] = []; + const issues = validateBrackets(text); - // diagnostics.push({ - // severity: DiagnosticSeverity.Information, - // range: { - // start: textDocument.positionAt(0), - // end: textDocument.positionAt(1), - // }, - // // message:`HI:(${text})(${result.hasErrors()},${result.hasWarnings()})`, - // message: `Parsing Failed`, - // source: 'test', - // }); + diagnostics.push( + ...issues.map(e => ({ + message: 'Brackets unmatched', + range: { + start: textDocument.positionAt(e), + end: textDocument.positionAt(e + 1), + }, + severity: DiagnosticSeverity.Error, + code: '[ and ]', + })) + ); - // Send the computed diagnostics to VSCode. - connection.sendDiagnostics({ uri: textDocument.uri, diagnostics }); + // Send the computed diagnostics to VSCode. + connection.sendDiagnostics({ uri: textDocument.uri, diagnostics }); } // This handler provides the initial list of the completion items. connection.onCompletion( - (_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => { - const completions: CompletionItem[] = [ - { - label: '+', - detail: 'Addition', - documentation: 'Add one to cell', - }, - { - label: '-', - detail: 'Subtraction', - documentation: 'Subtract one from cell', - }, - { - label: ',', - detail: 'Input', - documentation: 'Ask for input (Stored in the ASCII format)', - }, - { - label: '.', - detail: 'Output', - documentation: 'Output the equivalent ASCII character', - }, - { - label: '>', - detail: 'Right Shift', - documentation: 'Shift the pointer one cell to the right', - }, - { - label: '<', - detail: 'Left Shift', - documentation: 'Shift the pointer one cell to the Left', - }, - ]; - return completions.map(e => { - e.kind = CompletionItemKind.Operator; - return e; - }); - } + (_textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => { + const completions: CompletionItem[] = [ + { + label: '+', + detail: 'Addition', + documentation: 'Add one to cell', + }, + { + label: '-', + detail: 'Subtraction', + documentation: 'Subtract one from cell', + }, + { + label: ',', + detail: 'Input', + documentation: 'Ask for input (Stored in the ASCII format)', + }, + { + label: '.', + detail: 'Output', + documentation: 'Output the equivalent ASCII character', + }, + { + label: '>', + detail: 'Right Shift', + documentation: 'Shift the pointer one cell to the right', + }, + { + label: '<', + detail: 'Left Shift', + documentation: 'Shift the pointer one cell to the Left', + }, + ]; + return completions.map(e => { + e.kind = CompletionItemKind.Operator; + return e; + }); + } ); - // Make the text document manager listen on the connection // for open, change and close text document events documents.listen(connection);