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

Fix some routine CodeLens issues #1216

Merged
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
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