Skip to content

Make ObjectScript auto-comment delimiters configurable #1353

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 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
},
Expand Down
29 changes: 25 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<any> {
if (!packageJson.version.includes("SNAPSHOT")) {
try {
Expand Down Expand Up @@ -737,6 +742,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {

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,
Expand Down Expand Up @@ -971,9 +980,6 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
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()),
Expand Down Expand Up @@ -1149,6 +1155,18 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
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);
Expand Down Expand Up @@ -1382,4 +1400,7 @@ export function deactivate(): void {
if (terminals) {
terminals.forEach((t) => t.dispose());
}
macLangConf?.dispose();
incLangConf?.dispose();
intLangConf?.dispose();
}
8 changes: 7 additions & 1 deletion src/languageConfiguration.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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: [
Expand Down