Skip to content
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

Improve language configuration #1311

Merged
merged 3 commits into from
Feb 9, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/commands/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ async function importFile(
undefined,
true
);
documentContentProvider.update(serverUri.with({ scheme: "objectscript" }));
documentContentProvider.update(serverUri.with({ scheme: OBJECTSCRIPT_FILE_SCHEMA }));
})
.catch((error) => {
if (error?.statusCode == 409) {
Expand Down
5 changes: 3 additions & 2 deletions src/commands/documaticPreviewPanel.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode";
import { classNameRegex } from "../utils";
import { clsLangId } from "../extension";

/**
* The schema of the message that gets sent to the webview.
Expand Down Expand Up @@ -45,7 +46,7 @@ export class DocumaticPreviewPanel {
return;
}
const openDoc = openEditor.document;
if (openDoc.languageId !== "objectscript-class") {
if (openDoc.languageId !== clsLangId) {
// Documatic preview is for classes only
return;
}
Expand Down Expand Up @@ -278,7 +279,7 @@ export class DocumaticPreviewPanel {

vscode.window.onDidChangeActiveTextEditor(
async (editor: vscode.TextEditor) => {
if (editor !== undefined && editor.document.languageId === "objectscript-class") {
if (editor !== undefined && editor.document.languageId === clsLangId) {
// The new active editor is a class, so switch our preview to it

// Get the name of the current class
Expand Down
7 changes: 4 additions & 3 deletions src/commands/studioMigration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import util = require("util");
import { gte } from "semver";

import { fileExists, outputChannel } from "../utils";
import { clsLangId, cspLangId, incLangId, intLangId, macLangId } from "../extension";

/** Run a command using `node-cmd` and return a Promise */
const runCmd = util.promisify(cmd.run);
Expand Down Expand Up @@ -114,10 +115,10 @@ export async function loadStudioSnippets(): Promise<void> {
// Use Language to determine the scope
scope:
parts[1] == "5"
? "objectscript-csp"
? cspLangId
: parts[1] == "3"
? "objectscript-class"
: "objectscript,objectscript-int,objectscript-macros,objectscript-class,objectscript-csp",
? clsLangId
: `${macLangId},${intLangId},${incLangId},${clsLangId},${cspLangId}`,
};
}
});
Expand Down
6 changes: 3 additions & 3 deletions src/commands/unitTest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as vscode from "vscode";
import * as Atelier from "../api/atelier";
import { extensionId, filesystemSchemas, lsExtensionId } from "../extension";
import { clsLangId, extensionId, filesystemSchemas, lsExtensionId } from "../extension";
import { getFileText, methodOffsetToLine, outputChannel, stripClassMemberNameQuotes, uriIsParentOf } from "../utils";
import { fileSpecFromURI } from "../utils/FileProviderUtil";
import { AtelierAPI } from "../api";
Expand Down Expand Up @@ -998,7 +998,7 @@ export function setUpTestController(): vscode.Disposable[] {
// Create the initial root items
replaceRootTestItems(testController);

const openClass = vscode.workspace.textDocuments.find((d) => d.languageId == "objectscript-class");
const openClass = vscode.workspace.textDocuments.find((d) => d.languageId == clsLangId);
if (openClass) {
// Create TestItems for any test classes that are open at activation.
// Must be done after this extension activates because the resolve
Expand Down Expand Up @@ -1085,7 +1085,7 @@ export function setUpTestController(): vscode.Disposable[] {
vscode.workspace.onDidOpenTextDocument((document) => addItemForClassUri(testController, document.uri)),
vscode.workspace.onDidChangeTextDocument(async (e) => {
// If this is a test class, re-compute its TestItems
if (e.document.languageId == "objectscript-class") {
if (e.document.languageId == clsLangId) {
// Don't pass create flag because if it existed it would
// have been created already by the onDidOpen handler
const item = await getTestItemForClass(testController, e.document.uri);
Expand Down
42 changes: 23 additions & 19 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ export const schemas = [
];
export const filesystemSchemas = [FILESYSTEM_SCHEMA, FILESYSTEM_READONLY_SCHEMA];

export const clsLangId = "objectscript-class";
export const macLangId = "objectscript";
export const intLangId = "objectscript-int";
export const incLangId = "objectscript-macros";
export const cspLangId = "objectscript-csp";

import * as url from "url";
import path = require("path");
import {
Expand Down Expand Up @@ -717,35 +723,35 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
}
}),
vscode.languages.registerHoverProvider(
documentSelector("objectscript-class", "objectscript", "objectscript-int", "objectscript-macros"),
documentSelector(clsLangId, macLangId, intLangId, incLangId),
new ObjectScriptHoverProvider()
),
vscode.languages.registerDocumentFormattingEditProvider(
documentSelector("objectscript-class", "objectscript", "objectscript-int", "objectscript-macros"),
documentSelector(clsLangId, macLangId, intLangId, incLangId),
new DocumentFormattingEditProvider()
),
vscode.languages.registerDocumentRangeFormattingEditProvider(
documentSelector("objectscript-class", "objectscript", "objectscript-int", "objectscript-macros"),
documentSelector(clsLangId, macLangId, intLangId, incLangId),
new DocumentRangeFormattingEditProvider()
),
vscode.languages.registerDefinitionProvider(
documentSelector("objectscript-class", "objectscript", "objectscript-int", "objectscript-macros"),
documentSelector(clsLangId, macLangId, intLangId, incLangId),
new ObjectScriptDefinitionProvider()
),
vscode.languages.registerCompletionItemProvider(
documentSelector("objectscript-class", "objectscript", "objectscript-int", "objectscript-macros"),
documentSelector(clsLangId, macLangId, intLangId, incLangId),
new ObjectScriptCompletionItemProvider(),
"$",
"^",
".",
"#"
),
vscode.languages.registerDocumentSymbolProvider(
documentSelector("objectscript-class"),
documentSelector(clsLangId),
new ObjectScriptClassSymbolProvider()
),
vscode.languages.registerDocumentSymbolProvider(
documentSelector("objectscript", "objectscript-int"),
documentSelector(macLangId, intLangId),
new ObjectScriptRoutineSymbolProvider()
)
);
Expand All @@ -756,11 +762,11 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
if (semver.lt(lsVersion, "1.0.5")) {
context.subscriptions.push(
vscode.languages.registerFoldingRangeProvider(
documentSelector("objectscript-class"),
documentSelector(clsLangId),
new ObjectScriptClassFoldingRangeProvider()
),
vscode.languages.registerFoldingRangeProvider(
documentSelector("objectscript", "objectscript-int"),
documentSelector(macLangId, intLangId),
new ObjectScriptFoldingRangeProvider()
)
);
Expand Down Expand Up @@ -1008,19 +1014,17 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
isCaseSensitive: true,
isReadonly: true,
}),
vscode.languages.setLanguageConfiguration("objectscript-class", getLanguageConfiguration("class")),
vscode.languages.setLanguageConfiguration("objectscript", getLanguageConfiguration("routine")),
vscode.languages.setLanguageConfiguration("objectscript-macros", getLanguageConfiguration("routine")),
vscode.languages.registerCodeActionsProvider(
documentSelector("objectscript-class", "objectscript"),
new CodeActionProvider()
),
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()),
vscode.debug.registerDebugAdapterDescriptorFactory("objectscript", debugAdapterFactory),
debugAdapterFactory,
vscode.languages.registerCodeLensProvider(
documentSelector("objectscript-class", "objectscript", "objectscript-int"),
documentSelector(clsLangId, macLangId, intLangId),
new ObjectScriptCodeLensProvider()
),
vscode.commands.registerCommand("vscode-objectscript.compileOnly", () => compileOnly(false)),
Expand Down Expand Up @@ -1074,7 +1078,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
);
}),
vscode.window.onDidChangeActiveTextEditor((editor: vscode.TextEditor) => {
if (config("openClassContracted") && editor && editor.document.languageId === "objectscript-class") {
if (config("openClassContracted") && editor && editor.document.languageId === clsLangId) {
const uri: string = editor.document.uri.toString();
if (!openedClasses.includes(uri)) {
vscode.commands.executeCommand("editor.foldLevel1");
Expand Down Expand Up @@ -1237,7 +1241,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
vscode.window.onDidChangeTextEditorSelection((event: vscode.TextEditorSelectionChangeEvent) => {
posPanel.text = "";
const document = event.textEditor.document;
if (!["objectscript", "objectscript-int"].includes(document.languageId)) {
if (![macLangId, intLangId].includes(document.languageId)) {
return;
}
if (event.selections.length > 1 || !event.selections[0].isEmpty) {
Expand Down
50 changes: 15 additions & 35 deletions src/languageConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,52 +1,32 @@
import { IndentAction, LanguageConfiguration } from "vscode";
import * as vscode from "vscode";

export const WORD_PATTERN =
/((?<=(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;

export function getLanguageConfiguration(lang: string): LanguageConfiguration {
export function getLanguageConfiguration(lang: string): vscode.LanguageConfiguration {
return {
wordPattern: WORD_PATTERN,
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,
brackets: [
["{", "}"],
["(", ")"],
],
comments: {
lineComment: lang === "class" ? "//" : "#;",
lineComment: ["objectscript-class", "objectscript-int"].includes(lang) ? "//" : "#;",
blockComment: ["/*", "*/"],
gjsjohnmurray marked this conversation as resolved.
Show resolved Hide resolved
},
autoClosingPairs: [
{
open: "/*",
close: "*/",
notIn: [vscode.SyntaxTokenType.Comment, vscode.SyntaxTokenType.String, vscode.SyntaxTokenType.RegEx],
},
],
onEnterRules:
lang === "class"
lang == "objectscript-class"
? [
gjsjohnmurray marked this conversation as resolved.
Show resolved Hide resolved
{
beforeText: /^\/\/\//,
action: { indentAction: IndentAction.None, appendText: "/// " },
action: { indentAction: vscode.IndentAction.None, appendText: "/// " },
},
]
: [
{
beforeText: /^\s*\/\/\//,
action: { indentAction: IndentAction.None, appendText: "/// " },
},
{
beforeText: /^\s+\/\/[^/]?/,
action: { indentAction: IndentAction.None, appendText: "// " },
},
{
beforeText: /^\s+;;/,
action: { indentAction: IndentAction.None, appendText: ";; " },
},
{
beforeText: /^\s+;[^;]?/,
action: { indentAction: IndentAction.None, appendText: "; " },
},
{
beforeText: /^\s*#;/,
action: { indentAction: IndentAction.None, appendText: "#; " },
},
{
beforeText: /^\s*##;/,
action: { indentAction: IndentAction.None, appendText: "##; " },
},
],
: undefined,
};
}
7 changes: 4 additions & 3 deletions src/providers/FileDecorationProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as vscode from "vscode";
import { currentFile } from "../utils";
import { clsLangId, cspLangId, intLangId, macLangId } from "../extension";

export class FileDecorationProvider implements vscode.FileDecorationProvider {
private _genBadge = String.fromCharCode(9965); // Gear
Expand All @@ -20,13 +21,13 @@ export class FileDecorationProvider implements vscode.FileDecorationProvider {
if (
doc != undefined &&
!doc.isUntitled &&
["objectscript", "objectscript-class", "objectscript-int", "objectscript-macros"].includes(doc.languageId) &&
[clsLangId, macLangId, intLangId, cspLangId].includes(doc.languageId) &&
vscode.workspace
.getConfiguration("objectscript", vscode.workspace.getWorkspaceFolder(uri))
.get<boolean>("showGeneratedFileDecorations")
) {
// Use the file's contents to check if it's generated
if (doc.languageId == "objectscript-class") {
if (doc.languageId == clsLangId) {
for (let line = 0; line < doc.lineCount; line++) {
const lineText = doc.lineAt(line).text;
if (lineText.startsWith("Class ")) {
Expand All @@ -51,7 +52,7 @@ export class FileDecorationProvider implements vscode.FileDecorationProvider {
tooltip += ` by ${macMatch[1]}.cls`;
} else if (intMatch) {
tooltip += ` by ${intMatch[1]}.cls`;
} else if (doc.languageId == "objectscript-int") {
} else if (doc.languageId == intLangId) {
tooltip += ` by ${file.slice(0, -3)}mac`;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/providers/FileSystemProvider/FileSystemProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
redirectDotvscodeRoot,
workspaceFolderOfUri,
} from "../../utils/index";
import { config, workspaceState } from "../../extension";
import { config, intLangId, macLangId, workspaceState } from "../../extension";
import { addIsfsFileToProject, modifyProject } from "../../commands/project";
import { DocumentContentProvider } from "../DocumentContentProvider";
import { Document } from "../../api/atelier";
Expand Down Expand Up @@ -80,7 +80,7 @@ export function generateFileContent(
const routineName = fileName.split(".").slice(0, -1).join(".");
const routineType = fileExt != "mac" ? `[Type=${fileExt.toUpperCase()}]` : "";
if (sourceLines.length === 0 && fileExt !== "inc") {
const languageId = fileExt === "mac" ? "objectscript" : "objectscript-int";
const languageId = fileExt === "mac" ? macLangId : intLangId;

// Labels cannot contain dots
const firstLabel = routineName.replaceAll(".", "");
Expand Down
6 changes: 3 additions & 3 deletions src/providers/ObjectScriptCodeLensProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as vscode from "vscode";
import { config } from "../extension";
import { clsLangId, config, intLangId, macLangId } from "../extension";
import { currentFile } from "../utils";
import { AtelierAPI } from "../api";

Expand All @@ -8,10 +8,10 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
document: vscode.TextDocument,
token: vscode.CancellationToken
): vscode.ProviderResult<vscode.CodeLens[]> {
if (document.languageId == "objectscript-class") {
if (document.languageId == clsLangId) {
return this.classMembers(document);
}
if (["objectscript", "objectscript-int"].includes(document.languageId)) {
if ([macLangId, intLangId].includes(document.languageId)) {
return this.routineLabels(document);
}
return [];
Expand Down
4 changes: 2 additions & 2 deletions src/providers/RuleEditorProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as vscode from "vscode";
import { AtelierAPI } from "../api";
import { loadChanges } from "../commands/compile";
import { StudioActions } from "../commands/studio";
import { cspApps } from "../extension";
import { clsLangId, cspApps } from "../extension";
import { currentFile, outputChannel } from "../utils";

/**
Expand All @@ -28,7 +28,7 @@ export class RuleEditorProvider implements vscode.CustomTextEditorProvider {
token: vscode.CancellationToken
): Promise<void> {
// Check that document is a clean, well-formed class
if (document.languageId != "objectscript-class") {
if (document.languageId != clsLangId) {
return RuleEditorProvider._errorMessage(`${document.fileName} is not a class.`);
}
if (document.isUntitled) {
Expand Down
8 changes: 4 additions & 4 deletions src/web-extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
documentSelector("objectscript"),
new ObjectScriptRoutineSymbolProvider()
),
vscode.languages.setLanguageConfiguration("objectscript-class", getLanguageConfiguration("class")),
vscode.languages.setLanguageConfiguration("objectscript", getLanguageConfiguration("routine")),
vscode.languages.setLanguageConfiguration("objectscript-int", getLanguageConfiguration("routine")),
vscode.languages.setLanguageConfiguration("objectscript-macros", getLanguageConfiguration("routine"))
vscode.languages.setLanguageConfiguration("objectscript-class", getLanguageConfiguration("objectscript-class")),
vscode.languages.setLanguageConfiguration("objectscript", getLanguageConfiguration("objectscript")),
vscode.languages.setLanguageConfiguration("objectscript-int", getLanguageConfiguration("objectscript-int")),
vscode.languages.setLanguageConfiguration("objectscript-macros", getLanguageConfiguration("objectscript-macros"))
);
}

Expand Down