Skip to content

Commit

Permalink
Fix some routine CodeLens issues (#1216)
Browse files Browse the repository at this point in the history
  • Loading branch information
gjsjohnmurray authored Aug 18, 2023
1 parent 795a993 commit 3fadb63
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ export async function activate(context: vscode.ExtensionContext): Promise<any> {
vscode.debug.registerDebugAdapterDescriptorFactory("objectscript", debugAdapterFactory),
debugAdapterFactory,
vscode.languages.registerCodeLensProvider(
documentSelector("objectscript-class", "objectscript"),
documentSelector("objectscript-class", "objectscript", "objectscript-int"),
new ObjectScriptCodeLensProvider()
),
vscode.commands.registerCommand("vscode-objectscript.compileOnly", () => compileOnly(false)),
Expand Down
39 changes: 24 additions & 15 deletions src/providers/ObjectScriptCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,35 @@ export class ObjectScriptCodeLensProvider implements vscode.CodeLensProvider {
return result;
}

debugThisMethod && result.push(this.addDebugThisMethod(0, [`^${routineName}`, false]));
copyToClipboard && result.push(this.addCopyToClipboard(0, [`^${routineName}`]));

const symbols: vscode.DocumentSymbol[] = await vscode.commands.executeCommand(
"vscode.executeDocumentSymbolProvider",
document.uri
);
symbols
.filter((symbol) => symbol.kind === vscode.SymbolKind.Method)
.forEach((symbol) => {
const line = symbol.selectionRange.start.line;
const labelMatch = document.lineAt(line).text.match(/^(\w[^(\n\s]+)(?:\(([^)]*)\))?/i);
if (labelMatch) {
const [, name, parens] = labelMatch;

debugThisMethod && result.push(this.addDebugThisMethod(line, [`${name}^${routineName}`, parens !== "()"]));
copyToClipboard && result.push(this.addCopyToClipboard(line, [`${name}^${routineName}`]));
}
});

let labelledLine1 = false;
if (symbols) {
symbols
.filter((symbol) => symbol.kind === vscode.SymbolKind.Method)
.forEach((symbol) => {
const line = symbol.selectionRange.start.line;
const labelMatch = document.lineAt(line).text.match(/^(\w[^(\n\s]+)(?:\(([^)]*)\))?/i);
if (labelMatch) {
if (line === 1) {
labelledLine1 = true;
}
const [, name, parens] = labelMatch;
debugThisMethod &&
result.push(this.addDebugThisMethod(line, [`${name}^${routineName}`, parens && parens !== "()"]));
copyToClipboard && result.push(this.addCopyToClipboard(line, [`${name}^${routineName}`]));
}
});
}

// Add lenses at the top only if the first code line had no label
if (!labelledLine1) {
debugThisMethod && result.push(this.addDebugThisMethod(0, [`^${routineName}`, false]));
copyToClipboard && result.push(this.addCopyToClipboard(0, [`^${routineName}`]));
}
return result;
}

Expand Down

0 comments on commit 3fadb63

Please sign in to comment.