Skip to content

Commit d40effa

Browse files
authored
Expand allowed Unicode characters in class names (#1225)
1 parent 647ad14 commit d40effa

File tree

4 files changed

+19
-9
lines changed

4 files changed

+19
-9
lines changed

src/commands/compile.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
} from "../extension";
1515
import { DocumentContentProvider } from "../providers/DocumentContentProvider";
1616
import {
17+
classNameRegex,
1718
cspAppsForUri,
1819
CurrentBinaryFile,
1920
currentFile,
@@ -23,6 +24,7 @@ import {
2324
isClassDeployed,
2425
notNull,
2526
outputChannel,
27+
routineNameTypeRegex,
2628
throttleRequests,
2729
} from "../utils";
2830
import { PackageNode } from "../explorer/models/packageNode";
@@ -770,12 +772,12 @@ export async function importLocalFilesToServerSideFolder(wsFolderUri: vscode.Uri
770772
let ext = "";
771773
if (uri.path.split(".").pop().toLowerCase() == "cls") {
772774
// Allow Unicode letters
773-
const match = content.match(/^[ \t]*Class[ \t]+(%?[\p{L}\d]+(?:\.[\p{L}\d]+)+)/imu);
775+
const match = content.match(classNameRegex);
774776
if (match) {
775777
[, docName, ext = "cls"] = match;
776778
}
777779
} else {
778-
const match = content.match(/^ROUTINE ([^\s]+)(?:\s*\[\s*Type\s*=\s*\b([a-z]{3})\b)?/i);
780+
const match = content.match(routineNameTypeRegex);
779781
if (match) {
780782
[, docName, ext = "mac"] = match;
781783
} else {

src/commands/documaticPreviewPanel.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as vscode from "vscode";
2+
import { classNameRegex } from "../utils";
23

34
/**
45
* The schema of the message that gets sent to the webview.
@@ -59,7 +60,7 @@ export class DocumaticPreviewPanel {
5960

6061
// Get the name of the current class
6162
let clsname = "";
62-
const match = openDoc.getText().match(/^[ \t]*Class[ \t]+(%?[\p{L}\d]+(?:\.[\p{L}\d]+)+)/imu);
63+
const match = openDoc.getText().match(classNameRegex);
6364
if (match) {
6465
[, clsname] = match;
6566
}
@@ -282,7 +283,7 @@ export class DocumaticPreviewPanel {
282283

283284
// Get the name of the current class
284285
let clsname = "";
285-
const match = editor.document.getText().match(/^[ \t]*Class[ \t]+(%?[\p{L}\d]+(?:\.[\p{L}\d]+)+)/imu);
286+
const match = editor.document.getText().match(classNameRegex);
286287
if (match) {
287288
[, clsname] = match;
288289
}

src/providers/FileSystemProvider/FileSystemProvider.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { File } from "./File";
66
import { fireOtherStudioAction, OtherStudioAction } from "../../commands/studio";
77
import { projectContentsFromUri, studioOpenDialogFromURI } from "../../utils/FileProviderUtil";
88
import {
9+
classNameRegex,
910
isClassDeployed,
1011
notNull,
1112
outputChannel,
@@ -348,7 +349,7 @@ export class FileSystemProvider implements vscode.FileSystemProvider {
348349
}
349350
// Check if the class name and file name match
350351
let clsname = "";
351-
const match = content.toString().match(/^[ \t]*Class[ \t]+(%?[\p{L}\d]+(?:\.[\p{L}\d]+)+)/imu);
352+
const match = content.toString().match(classNameRegex);
352353
if (match) {
353354
[, clsname] = match;
354355
}

src/utils/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@ export function isImportableLocalFile(file: vscode.TextDocument): boolean {
148148
}
149149
}
150150

151+
/** A regex for extracting the name of a class from its content */
152+
export const classNameRegex = /^[ \t]*Class[ \t]+(%?[\p{L}\d\u{100}-\u{ffff}]+(?:\.[\p{L}\d\u{100}-\u{ffff}]+)+)/imu;
153+
154+
/** A regex for extracting the name and type of a routine from its content */
155+
export const routineNameTypeRegex = /^ROUTINE ([^\s]+)(?:\s*\[\s*Type\s*=\s*\b([a-z]{3})\b)?/i;
156+
151157
export function currentFileFromContent(uri: vscode.Uri, content: string | Buffer): CurrentTextFile | CurrentBinaryFile {
152158
const fileName = uri.fsPath;
153159
const workspaceFolder = workspaceFolderOfUri(uri);
@@ -160,12 +166,12 @@ export function currentFileFromContent(uri: vscode.Uri, content: string | Buffer
160166
let ext = "";
161167
if (fileExt === "cls" && typeof content === "string") {
162168
// Allow Unicode letters
163-
const match = content.match(/^[ \t]*Class[ \t]+(%?[\p{L}\d]+(?:\.[\p{L}\d]+)+)/imu);
169+
const match = content.match(classNameRegex);
164170
if (match) {
165171
[, name, ext = "cls"] = match;
166172
}
167173
} else if (fileExt.match(/(mac|int|inc)/i) && typeof content === "string") {
168-
const match = content.match(/^ROUTINE ([^\s]+)(?:\s*\[\s*Type\s*=\s*\b([a-z]{3})\b)?/i);
174+
const match = content.match(routineNameTypeRegex);
169175
if (match) {
170176
[, name, ext = "mac"] = match;
171177
} else {
@@ -244,12 +250,12 @@ export function currentFile(document?: vscode.TextDocument): CurrentTextFile {
244250
name = uri.path;
245251
} else if (fileExt === "cls") {
246252
// Allow Unicode letters
247-
const match = content.match(/^[ \t]*Class[ \t]+(%?[\p{L}\d]+(?:\.[\p{L}\d]+)+)/imu);
253+
const match = content.match(classNameRegex);
248254
if (match) {
249255
[, name, ext = "cls"] = match;
250256
}
251257
} else if (fileExt.match(/(mac|int|inc)/i)) {
252-
const match = content.match(/^ROUTINE ([^\s]+)(?:\s*\[\s*Type\s*=\s*\b([a-z]{3})\b)?/i);
258+
const match = content.match(routineNameTypeRegex);
253259
if (match) {
254260
[, name, ext = "mac"] = match;
255261
} else {

0 commit comments

Comments
 (0)