[reword]
This commit is contained in:
@@ -4,9 +4,9 @@ import { bfVisitor } from './generated/bfVisitor';
|
|||||||
import { DiagnosticSeverity } from 'vscode-languageclient';
|
import { DiagnosticSeverity } from 'vscode-languageclient';
|
||||||
import { getTree } from './BranFlakesParseRunner';
|
import { getTree } from './BranFlakesParseRunner';
|
||||||
import { RuleNode } from 'antlr4ts/tree/RuleNode';
|
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<Promise<void>>
|
extends AbstractParseTreeVisitor<Promise<void>>
|
||||||
implements bfVisitor<Promise<void>>
|
implements bfVisitor<Promise<void>>
|
||||||
{
|
{
|
||||||
|
4
client/src/command/BranFlakesCommand.ts
Normal file
4
client/src/command/BranFlakesCommand.ts
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
export interface BranFlakesCommand {
|
||||||
|
getCommandName(): string;
|
||||||
|
getCommandHandler(): (...args: any) => Promise<any>;
|
||||||
|
}
|
@@ -1,5 +0,0 @@
|
|||||||
|
|
||||||
export interface Command{
|
|
||||||
getCommandName():string;
|
|
||||||
getCommandHandler():(...args:any)=>Promise<any>;
|
|
||||||
}
|
|
@@ -1,7 +1,6 @@
|
|||||||
import { window } from 'vscode';
|
import { window } from 'vscode';
|
||||||
import { Command as BranFlakesCommand } from './Command';
|
import type { BranFlakesCommand } from './BranFlakesCommand';
|
||||||
import { VSCodePromptInputStrategy } from '../input/VSCodePromptInputStrategy';
|
import { VSCodePromptInputStrategy } from '../input/VSCodePromptInputStrategy';
|
||||||
import BranFlakesExecutorVisitor from '../BranFlakesExecutorVisitor';
|
|
||||||
|
|
||||||
export class CompileBranFlakesCommand implements BranFlakesCommand {
|
export class CompileBranFlakesCommand implements BranFlakesCommand {
|
||||||
getCommandName() {
|
getCommandName() {
|
||||||
@@ -14,6 +13,10 @@ export class CompileBranFlakesCommand implements BranFlakesCommand {
|
|||||||
const inputStrategy = new VSCodePromptInputStrategy(
|
const inputStrategy = new VSCodePromptInputStrategy(
|
||||||
window.showInputBox
|
window.showInputBox
|
||||||
);
|
);
|
||||||
|
const { BranFlakesExecutorVisitor } = await import(
|
||||||
|
'../BranFlakesExecutorVisitor'
|
||||||
|
);
|
||||||
|
|
||||||
const output = await BranFlakesExecutorVisitor.run(
|
const output = await BranFlakesExecutorVisitor.run(
|
||||||
text,
|
text,
|
||||||
fn,
|
fn,
|
@@ -4,14 +4,15 @@
|
|||||||
* ------------------------------------------------------------------------------------------ */
|
* ------------------------------------------------------------------------------------------ */
|
||||||
|
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import { ExtensionContext, commands, window } from 'vscode';
|
import { commands } from 'vscode';
|
||||||
|
import type { ExtensionContext } from 'vscode';
|
||||||
import {
|
import {
|
||||||
LanguageClient,
|
LanguageClient,
|
||||||
LanguageClientOptions,
|
LanguageClientOptions,
|
||||||
ServerOptions,
|
ServerOptions,
|
||||||
TransportKind,
|
TransportKind,
|
||||||
} from 'vscode-languageclient';
|
} from 'vscode-languageclient';
|
||||||
import { CompileBranFlakesCommand } from './command/CompileCommand';
|
import { CompileBranFlakesCommand } from './command/CompileBranFlakesCommand';
|
||||||
|
|
||||||
let client: LanguageClient;
|
let client: LanguageClient;
|
||||||
|
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
import { CancellationToken, InputBoxOptions } from 'vscode';
|
import type { CancellationToken, InputBoxOptions } from 'vscode';
|
||||||
import InputStrategy from './InputStrategy';
|
import type InputStrategy from './InputStrategy';
|
||||||
|
|
||||||
export class VSCodePromptInputStrategy implements InputStrategy {
|
export class VSCodePromptInputStrategy implements InputStrategy {
|
||||||
private inputQueue: string = '';
|
private inputQueue: string = '';
|
||||||
|
@@ -5,9 +5,9 @@
|
|||||||
"author": "Atreya Bain",
|
"author": "Atreya Bain",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"publisher": "atreyabain",
|
"publisher": "atreyabain",
|
||||||
"version": "0.2.0",
|
"version": "0.2.1",
|
||||||
"icon": "assets/128.png",
|
"icon": "assets/128.png",
|
||||||
"categories": [],
|
"categories": ["Programming Languages","Linters"],
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"multi-root ready",
|
"multi-root ready",
|
||||||
"brainfuck",
|
"brainfuck",
|
||||||
|
@@ -15,19 +15,14 @@ import {
|
|||||||
TextDocumentPositionParams,
|
TextDocumentPositionParams,
|
||||||
TextDocumentSyncKind,
|
TextDocumentSyncKind,
|
||||||
InitializeResult,
|
InitializeResult,
|
||||||
Position,
|
|
||||||
} from 'vscode-languageserver';
|
} from 'vscode-languageserver';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
import { TextDocument } from 'vscode-languageserver-textdocument';
|
import { TextDocument } from 'vscode-languageserver-textdocument';
|
||||||
|
|
||||||
|
|
||||||
// Create a connection for the server. The connection uses Node's IPC as a transport.
|
// Create a connection for the server. The connection uses Node's IPC as a transport.
|
||||||
// Also include all preview / proposed LSP features.
|
// Also include all preview / proposed LSP features.
|
||||||
let connection = createConnection(ProposedFeatures.all);
|
let connection = createConnection(ProposedFeatures.all);
|
||||||
|
|
||||||
|
|
||||||
// Create a simple text document manager. The text document manager
|
// Create a simple text document manager. The text document manager
|
||||||
// supports full document sync only
|
// supports full document sync only
|
||||||
let documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
let documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument);
|
||||||
@@ -113,7 +108,9 @@ connection.onDidChangeConfiguration(change => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Revalidate all open text documents
|
// Revalidate all open text documents
|
||||||
documents.all().forEach(validateTextDocument);
|
Promise.all(documents.all().map(validateTextDocument)).catch(e => {
|
||||||
|
connection.console.log('Failed to validate text documents');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function getDocumentSettings(resource: string): Thenable<ExampleSettings> {
|
function getDocumentSettings(resource: string): Thenable<ExampleSettings> {
|
||||||
@@ -139,7 +136,6 @@ documents.onDidClose(e => {
|
|||||||
// The content of a text document has changed. This event is emitted
|
// The content of a text document has changed. This event is emitted
|
||||||
// when the text document first opened or when its content has changed.
|
// when the text document first opened or when its content has changed.
|
||||||
documents.onDidChangeContent(change => {
|
documents.onDidChangeContent(change => {
|
||||||
//change.contentChanges;
|
|
||||||
validateTextDocument(change.document);
|
validateTextDocument(change.document);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -149,17 +145,22 @@ documents.onDidSave(change => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const validateBrackets = (text: string) => {
|
const validateBrackets = (text: string) => {
|
||||||
let count = 0, lp: number[] = [],issues:number[]=[];
|
let count = 0,
|
||||||
|
lp: number[] = [],
|
||||||
|
issues: number[] = [];
|
||||||
const textsplit = text.split('');
|
const textsplit = text.split('');
|
||||||
textsplit.forEach((x, i) => {
|
textsplit.forEach((x, i) => {
|
||||||
if (x === '[' || x === ']') {
|
if (x === '[' || x === ']') {
|
||||||
|
if (x === '[') {
|
||||||
if (x === '[') {lp.push(i);}
|
lp.push(i);
|
||||||
if (x === ']') {if(lp.length===0) {issues.push(i);}lp.pop();}
|
}
|
||||||
|
if (x === ']') {
|
||||||
|
if (lp.length === 0) {
|
||||||
|
issues.push(i);
|
||||||
|
}
|
||||||
|
lp.pop();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return [...lp, ...issues];
|
return [...lp, ...issues];
|
||||||
@@ -175,7 +176,8 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
|
|||||||
let diagnostics: Diagnostic[] = [];
|
let diagnostics: Diagnostic[] = [];
|
||||||
const issues = validateBrackets(text);
|
const issues = validateBrackets(text);
|
||||||
|
|
||||||
diagnostics.push(...issues.map<Diagnostic>(e => ({
|
diagnostics.push(
|
||||||
|
...issues.map<Diagnostic>(e => ({
|
||||||
message: 'Brackets unmatched',
|
message: 'Brackets unmatched',
|
||||||
range: {
|
range: {
|
||||||
start: textDocument.positionAt(e),
|
start: textDocument.positionAt(e),
|
||||||
@@ -183,26 +185,8 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
|
|||||||
},
|
},
|
||||||
severity: DiagnosticSeverity.Error,
|
severity: DiagnosticSeverity.Error,
|
||||||
code: '[ and ]',
|
code: '[ and ]',
|
||||||
})));
|
}))
|
||||||
|
);
|
||||||
// diagnostics.push({
|
|
||||||
// message: 'Brackets not matched',
|
|
||||||
// range: {
|
|
||||||
// start: { line: 0, character: 0 },
|
|
||||||
// end: { line: 0, character: 0 },
|
|
||||||
// },
|
|
||||||
// });
|
|
||||||
|
|
||||||
// diagnostics.push(<Diagnostic>{
|
|
||||||
// severity: DiagnosticSeverity.Information,
|
|
||||||
// range: {
|
|
||||||
// start: textDocument.positionAt(0),
|
|
||||||
// end: textDocument.positionAt(1),
|
|
||||||
// },
|
|
||||||
// // message:`HI:(${text})(${result.hasErrors()},${result.hasWarnings()})`,
|
|
||||||
// message: `Parsing Failed`,
|
|
||||||
// source: 'test',
|
|
||||||
// });
|
|
||||||
|
|
||||||
// Send the computed diagnostics to VSCode.
|
// Send the computed diagnostics to VSCode.
|
||||||
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
|
||||||
@@ -250,7 +234,6 @@ connection.onCompletion(
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// Make the text document manager listen on the connection
|
// Make the text document manager listen on the connection
|
||||||
// for open, change and close text document events
|
// for open, change and close text document events
|
||||||
documents.listen(connection);
|
documents.listen(connection);
|
||||||
|
Reference in New Issue
Block a user