diff --git a/.clang-format b/.clang-format index a12c0f2..1d43473 100644 --- a/.clang-format +++ b/.clang-format @@ -2,4 +2,6 @@ Language: JavaScript BasedOnStyle: Microsoft ColumnLimit: 0 AlignOperands: AlignAfterOperator -AlignConsecutiveAssignments: AcrossEmptyLinesAndComments \ No newline at end of file +AlignConsecutiveAssignments: AcrossEmptyLinesAndComments +IndentWidth: 4 +TabWidth: 4 \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..d0eb788 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "editor.formatOnSave": true, + "[typescript]": { + "editor.defaultFormatter": "xaver.clang-format" + } +} diff --git a/package.json b/package.json index a7c57c2..65da06a 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,16 @@ "type": "string", "default": "error", "description": "Log level for sclang language server {info, debug, warning, error, critical, all}" + }, + "supercollider.codeEvaluation.blinkDuration": { + "type": "number", + "default": 600, + "description": "The amount of time to highlight the executed code" + }, + "supercollider.codeEvaluation.showMessage": { + "type": "boolean", + "default": false, + "description": "Show a message toast after code execution" } } } diff --git a/src/commands/evaluate.ts b/src/commands/evaluate.ts index 024aa89..0ccc7a8 100644 --- a/src/commands/evaluate.ts +++ b/src/commands/evaluate.ts @@ -26,20 +26,19 @@ const evaluateDecorator = vscode.window.createTextEditorDecorationType({ backgroundColor : new vscode.ThemeColor('inputOption.activeBackground'), isWholeLine : true, }); -const successDecorator = vscode.window.createTextEditorDecorationType({ +const successDecorator = vscode.window.createTextEditorDecorationType({ // backgroundColor : new vscode.ThemeColor('inputValidation.infoBackground'), overviewRulerColor : new vscode.ThemeColor('inputValidation.infoBackground'), outline : 'border-left-width: 1px', isWholeLine : true, }); -const errorDecorator = vscode.window.createTextEditorDecorationType({ +const errorDecorator = vscode.window.createTextEditorDecorationType({ backgroundColor : new vscode.ThemeColor('inputValidation.errorBackground'), overviewRulerColor : new vscode.ThemeColor('inputValidation.infoBackground'), outline : 'border-left-width: 1px', isWholeLine : true, - }); + }); let evaluateCount = 0; -const decoratorTimeout = 5000; // Start and end execution actions function onEndEvaluate(textEditor: TextEditor, range: Range, responseText: string, isError: boolean) @@ -64,9 +63,9 @@ function onEndEvaluate(textEditor: TextEditor, range: Range, responseText: strin } } -function onStartEvaluate(textEditor: TextEditor, range: Range) +function onStartEvaluate(textEditor: TextEditor, range: Range, codeEvaluationSettings: SuperColliderContext["codeEvaluationSettings"]) { - let currentEvaluateCount = ++ evaluateCount; + let currentEvaluateCount = ++evaluateCount; textEditor.setDecorations(successDecorator, []) textEditor.setDecorations(errorDecorator, []) @@ -81,10 +80,10 @@ function onStartEvaluate(textEditor: TextEditor, range: Range) { textEditor.setDecorations(evaluateDecorator, []); } - }, decoratorTimeout); + }, codeEvaluationSettings.blinkDuration); return (text: string, isError: boolean) => { - if (evaluateCount == currentEvaluateCount) + if (evaluateCount != currentEvaluateCount) { onEndEvaluate(textEditor, range, text, isError) } @@ -110,8 +109,8 @@ function currentDocumentLine() let startLine = activeTextEditor.document.lineAt(selection.start); let endLine = activeTextEditor.document.lineAt(selection.end); let range = new Range( - startLine.range.start, - endLine.range.end); + startLine.range.start, + endLine.range.end); return range; } @@ -174,8 +173,9 @@ function currentDocumentRegion() } } -interface EvaluateSelectionProvider { - evaluateString(document: vscode.TextDocument, range: vscode.Selection): vscode.ProviderResult; +interface EvaluateSelectionProvider +{ + evaluateString(document: vscode.TextDocument, range: vscode.Selection, context: SuperColliderContext): vscode.ProviderResult; } export function registerEvaluateProvider(context: SuperColliderContext, provider): vscode.Disposable @@ -188,10 +188,10 @@ export function registerEvaluateProvider(context: SuperColliderContext, provider (inputRange) => { const document = vscode.window.activeTextEditor.document; const range = (inputRange != null) - ? new vscode.Selection( - new vscode.Position(inputRange['start']['line'], inputRange['start']['character']), - new vscode.Position(inputRange['end']['line'], inputRange['end']['character'])) - : currentDocumentSelection(); + ? new vscode.Selection( + new vscode.Position(inputRange['start']['line'], inputRange['start']['character']), + new vscode.Position(inputRange['end']['line'], inputRange['end']['character'])) + : currentDocumentSelection(); if (range !== null) { @@ -228,11 +228,9 @@ export function registerEvaluateProvider(context: SuperColliderContext, provider }) } -interface EvaluateSelectionOptions extends WorkDoneProgressOptions { -} +type EvaluateSelectionOptions = WorkDoneProgressOptions; -interface EvaluateSelectionRegistrationOptions extends EvaluateSelectionOptions, TextDocumentRegistrationOptions, StaticRegistrationOptions { -} +type EvaluateSelectionRegistrationOptions = EvaluateSelectionOptions&TextDocumentRegistrationOptions&StaticRegistrationOptions; namespace EvaluateSelectionRequest { @@ -252,7 +250,7 @@ export interface EvaluateSelectionResult { export const type = new ProtocolRequestType(method); } -async function evaluateString(client: vscodelc.BaseLanguageClient, document: vscode.TextDocument, range: Range): Promise +async function evaluateString(client: vscodelc.BaseLanguageClient, document: vscode.TextDocument, range: Range, context: SuperColliderContext): Promise { const activeTextEditor = vscode.window.activeTextEditor; @@ -262,7 +260,7 @@ async function evaluateString(client: vscodelc.BaseLanguageClient, document: vsc const uri = vscode.Uri.file(document.fileName); const docIdentifier = vscodelc.TextDocumentIdentifier.create(uri.toString()); - let finishFunc = onStartEvaluate(activeTextEditor, range); + let finishFunc = onStartEvaluate(activeTextEditor, range, context.codeEvaluationSettings); const result = client.sendRequest(EvaluateSelectionRequest.type, { textDocument : docIdentifier, @@ -270,22 +268,30 @@ async function evaluateString(client: vscodelc.BaseLanguageClient, document: vsc }); result.then((result) => { + const prefix = '⇒ '; + if (result.result !== undefined) { - const prefix = '⇒ '; - vscode.window.showInformationMessage(prefix + result.result); + if (context.codeEvaluationSettings.showMessage) + { + vscode.window.showInformationMessage(prefix + result.result); + } finishFunc(result.result, false); } else if (result.compileError !== undefined) { - const prefix = '⇏ '; - vscode.window.showErrorMessage(prefix + result.compileError); + if (context.codeEvaluationSettings.showMessage) + { + vscode.window.showErrorMessage(prefix + result.compileError); + } finishFunc(result.compileError, true); } else if (result.error !== undefined) { - const prefix = '⇏ '; - vscode.window.showErrorMessage(prefix + result.error); + if (context.codeEvaluationSettings.showMessage) + { + vscode.window.showErrorMessage(prefix + result.error); + } finishFunc(result.error, true); } }); @@ -299,7 +305,7 @@ export class EvaluateSelectionFeature extends TextDocumentFeature { - const client = this._client; + const client = this._client; - const provideEvaluateSelection = (document: vscode.TextDocument, range: vscode.Selection) => { - return evaluateString(client, document, range); + const provideEvaluateSelection = (document: vscode.TextDocument, range: vscode.Selection, context: SuperColliderContext) => { + return evaluateString(client, document, range, context); }; - return provideEvaluateSelection(document, range); + return provideEvaluateSelection(document, range, this._context); } }; diff --git a/src/context.ts b/src/context.ts index b26ac07..412c3be 100644 --- a/src/context.ts +++ b/src/context.ts @@ -33,24 +33,30 @@ export class SuperColliderContext implements Disposable sclangProcess: cp.ChildProcess; lspTokenPath: string; outputChannel: vscode.OutputChannel; + codeEvaluationSettings: { + blinkDuration: number; + showMessage : boolean; + }; processOptions() { - const configuration = workspace.getConfiguration() + const configuration = workspace.getConfiguration(); - const sclangPath = configuration.get('supercollider.sclang.cmd') - const sclangArgs = configuration.get>('supercollider.sclang.args') - const sclangEnv = configuration.get('supercollider.sclang.environment') - const sclangConfYaml = configuration.get('supercollider.sclang.confYaml') + const sclangPath = configuration.get('supercollider.sclang.cmd'); + const sclangArgs = configuration.get>('supercollider.sclang.args'); + const sclangEnv = configuration.get('supercollider.sclang.environment'); + const sclangConfYaml = configuration.get('supercollider.sclang.confYaml'); - const readPort = configuration.get('supercollider.sclang.lspReadPort') - const writePort = configuration.get('supercollider.sclang.lspWritePort') + const readPort = configuration.get('supercollider.sclang.lspReadPort'); + const writePort = configuration.get('supercollider.sclang.lspWritePort'); + + this.codeEvaluationSettings = configuration.get('supercollider.codeEvaluation') let env = process.env; env['SCLANG_LSP_ENABLE'] = '1'; env['SCLANG_LSP_SERVERPORT'] = readPort.toString(); env['SCLANG_LSP_CLIENTPORT'] = writePort.toString(); - env['SCLANG_LSP_LOGLEVEL'] = configuration.get('supercollider.languageServerLogLevel') + env['SCLANG_LSP_LOGLEVEL'] = configuration.get('supercollider.languageServerLogLevel'); let spawnOptions: cp.SpawnOptions = { env : Object.assign(env, sclangEnv) @@ -113,7 +119,7 @@ export class SuperColliderContext implements Disposable let sclangProcess = this.sclangProcess = this.createProcess(); const serverOptions: ServerOptions = function() { - // @TODO what if terminal launch fails? + // @TODO what if terminal launch fails? const configuration = workspace.getConfiguration() const readPort = configuration.get('supercollider.sclang.lspReadPort') @@ -135,10 +141,10 @@ export class SuperColliderContext implements Disposable res(streamInfo); } outputChannel.append(string); - }); + }); sclangProcess.on('exit', (code, signal) => { sclangProcess = null; }); - }); + }); }); };