diff --git a/package.json b/package.json index b4020c53..faca466e 100644 --- a/package.json +++ b/package.json @@ -1573,6 +1573,25 @@ "type": "boolean", "default": true, "scope": "resource" + }, + "objectscript.commentToken": { + "description": "The line comment characters for ObjectScript in classes and MAC and INC routines.", + "type": "string", + "enum": ["#;","//",";"], + "enumDescriptions": [ + "Comments do not appear in generated INT code.", + "Comments appear in generated INT code.", + "Comments appear in generated INT code." + ], + "default": "#;", + "scope": "machine" + }, + "objectscript.intCommentToken": { + "description": "The line comment characters for INT routines.", + "type": "string", + "enum": ["//",";"], + "default": "//", + "scope": "machine" } } }, diff --git a/src/extension.ts b/src/extension.ts index a01957ed..b08704e1 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -540,9 +540,14 @@ function proposedApiPrompt(active: boolean, added?: readonly vscode.WorkspaceFol } } -// The URIs of all classes that have been opened. Used when objectscript.openClassContracted is true. +/** The URIs of all classes that have been opened. Used when `objectscript.openClassContracted` is true */ let openedClasses: string[]; +// Disposables for language configurations that can be modifed by settings +let macLangConf: vscode.Disposable; +let incLangConf: vscode.Disposable; +let intLangConf: vscode.Disposable; + export async function activate(context: vscode.ExtensionContext): Promise { if (!packageJson.version.includes("SNAPSHOT")) { try { @@ -737,6 +742,10 @@ export async function activate(context: vscode.ExtensionContext): Promise { iscIcon = vscode.Uri.joinPath(context.extensionUri, "images", "fileIcon.svg"); + macLangConf = vscode.languages.setLanguageConfiguration(macLangId, getLanguageConfiguration(macLangId)); + incLangConf = vscode.languages.setLanguageConfiguration(incLangId, getLanguageConfiguration(incLangId)); + intLangConf = vscode.languages.setLanguageConfiguration(intLangId, getLanguageConfiguration(intLangId)); + context.subscriptions.push( reporter, panel, @@ -971,9 +980,6 @@ export async function activate(context: vscode.ExtensionContext): Promise { isReadonly: true, }), vscode.languages.setLanguageConfiguration(clsLangId, getLanguageConfiguration(clsLangId)), - vscode.languages.setLanguageConfiguration(macLangId, getLanguageConfiguration(macLangId)), - vscode.languages.setLanguageConfiguration(incLangId, getLanguageConfiguration(incLangId)), - vscode.languages.setLanguageConfiguration(intLangId, getLanguageConfiguration(intLangId)), vscode.languages.registerCodeActionsProvider(documentSelector(clsLangId, macLangId), new CodeActionProvider()), vscode.languages.registerWorkspaceSymbolProvider(new WorkspaceSymbolProvider()), vscode.debug.registerDebugConfigurationProvider("objectscript", new ObjectScriptConfigurationProvider()), @@ -1149,6 +1155,18 @@ export async function activate(context: vscode.ExtensionContext): Promise { vscode.commands.executeCommand("workbench.files.action.refreshFilesExplorer"); } } + if (affectsConfiguration("objectscript.commentToken")) { + // Update the language configuration for "objectscript" and "objectscript-macros" + macLangConf?.dispose(); + incLangConf?.dispose(); + macLangConf = vscode.languages.setLanguageConfiguration(macLangId, getLanguageConfiguration(macLangId)); + incLangConf = vscode.languages.setLanguageConfiguration(incLangId, getLanguageConfiguration(incLangId)); + } + if (affectsConfiguration("objectscript.intCommentToken")) { + // Update the language configuration for "objectscript-int" + intLangConf?.dispose(); + intLangConf = vscode.languages.setLanguageConfiguration(intLangId, getLanguageConfiguration(intLangId)); + } }), vscode.window.onDidCloseTerminal((t) => { const terminalIndex = terminals.findIndex((terminal) => terminal.name == t.name); @@ -1382,4 +1400,7 @@ export function deactivate(): void { if (terminals) { terminals.forEach((t) => t.dispose()); } + macLangConf?.dispose(); + incLangConf?.dispose(); + intLangConf?.dispose(); } diff --git a/src/languageConfiguration.ts b/src/languageConfiguration.ts index abcbec22..e41aef61 100644 --- a/src/languageConfiguration.ts +++ b/src/languageConfiguration.ts @@ -1,6 +1,7 @@ import * as vscode from "vscode"; export function getLanguageConfiguration(lang: string): vscode.LanguageConfiguration { + const conf = vscode.workspace.getConfiguration("objectscript"); return { wordPattern: /((?<=(class|extends|as|of) )(%?\b[a-z0-9]+(\.[a-z0-9]+)*\b))|(\^[a-z0-9]+(\.[a-z0-9]+)*)|((\${1,3}|[irm]?%|\^|#)?[a-z0-9]+)/i, @@ -9,7 +10,12 @@ export function getLanguageConfiguration(lang: string): vscode.LanguageConfigura ["(", ")"], ], comments: { - lineComment: ["objectscript-class", "objectscript-int"].includes(lang) ? "//" : "#;", + lineComment: + lang == "objectscript-class" + ? "//" + : ["objectscript", "objectscript-macros"].includes(lang) + ? conf.get("commentToken") + : conf.get("intCommentToken"), blockComment: ["/*", "*/"], }, autoClosingPairs: [