Fix various bugs in vscode extension (#5772)

* Fix bugs

* Fix bugs

* Revert "Fix bugs"

This reverts commit 608639eb22.
This commit is contained in:
JeremyFunk
2023-09-20 19:09:51 +02:00
committed by GitHub
parent 689b28455c
commit 711a2bcdd1
3 changed files with 85 additions and 9 deletions

View File

@@ -0,0 +1,70 @@
.mtk1 { color: #cccccc; }
.mtk2 { color: #1f1f1f; }
.mtk3 { color: #d4d4d4; }
.mtk4 { color: #000080; }
.mtk5 { color: #6a9955; }
.mtk6 { color: #569cd6; }
.mtk7 { color: #b5cea8; }
.mtk8 { color: #646695; }
.mtk9 { color: #d7ba7d; }
.mtk10 { color: #9cdcfe; }
.mtk11 { color: #f44747; }
.mtk12 { color: #ce9178; }
.mtk13 { color: #6796e6; }
.mtk14 { color: #808080; }
.mtk15 { color: #d16969; }
.mtk16 { color: #dcdcaa; }
.mtk17 { color: #4ec9b0; }
.mtk18 { color: #c586c0; }
.mtk19 { color: #4fc1ff; }
.mtk20 { color: #c8c8c8; }
.mtk21 { color: #606060; }
.mtk22 { color: #ffffff; }
.mtk23 { color: #cd9731; }
.mtk24 { color: #b267e6; }
.mtki { font-style: italic; }
.mtkb { font-weight: bold; }
.mtku { text-decoration: underline; text-underline-position: under; }
.mtks { text-decoration: line-through; }
.mtks.mtku { text-decoration: underline line-through; text-underline-position: under; }
.bunlock {
display: flex;
flex-direction: row;
}
.lines {
display: flex;
flex-direction: column;
width: 30px;
margin-right: 15px;
text-align: right;
opacity: 0.5;
font-size: var(--vscode-editor-font-size);
font-weight: var(--vscode-editor-font-weight);
font-family: var(--vscode-editor-font-family);
background-color: var(--vscode-editor-background);
}
.lines > span {
margin-top: 1px;
margin-bottom: 1px;
}
code {
white-space: pre;
font-size: var(--vscode-editor-font-size);
font-weight: var(--vscode-editor-font-weight);
font-family: var(--vscode-editor-font-family);
background-color: var(--vscode-editor-background);
}
code > span {
display: inline-block;
width: 100%;
margin-top: 1px;
margin-bottom: 1px;
}

View File

@@ -8,8 +8,10 @@
"mime-db": "^1.52.0"
},
"scripts": {
"run": "hello.js",
"start": "bun hello.js"
"run": "node hello.js",
"start": "hello.js",
"start:bun": "bun hello.js",
"start:bun:quotes": "bun run hello.js"
},
"trustedDependencies": [
"mime"

View File

@@ -25,7 +25,7 @@ export async function providePackageJsonTasks(): Promise<BunTask[]> {
return Object.entries(scripts).map(([name, script]) => {
// Prefix script with bun if it doesn't already start with bun
const shellCommand = script.startsWith("bun") ? script : `bun ${script}`;
const shellCommand = script.startsWith("bun run ") ? script : `bun run ${script}`;
const task = new BunTask({
script,
@@ -55,10 +55,12 @@ function extractScriptsFromPackageJson(document: vscode.TextDocument) {
const range = new vscode.Range(document.positionAt(startIndex), document.positionAt(endIndex));
const scripts = matches[1].split(/,\s*/).map(script => {
const [name, command] = script.split(/s*:\s*/);
const elements = script.match(/"([^"\\]|\\.|\\\n)*"/g)
if(elements?.length != 2) return null
const [name, command] = elements
return {
name: name.replace(/"/g, "").trim(),
command: command.replace(/"/g, "").trim(),
name: name.replace('"', "").trim(),
command: command.replace(/(?<!\\)"/g, "").trim(),
range: new vscode.Range(
document.positionAt(startIndex + matches[0].indexOf(name)),
document.positionAt(startIndex + matches[0].indexOf(name) + name.length + command.length),
@@ -175,23 +177,25 @@ function registerHoverProvider(context: vscode.ExtensionContext) {
},
}),
vscode.commands.registerCommand("extension.bun.codelens.debug.task", async ({ script, name }: CommandArgs) => {
if (script.startsWith("bun run ")) script = script.slice(8);
if (script.startsWith("bun ")) script = script.slice(4);
debugCommand(script);
}),
vscode.commands.registerCommand("extension.bun.codelens.run.task", async ({ script, name }: CommandArgs) => {
if (script.startsWith("bun ")) script = script.slice(4);
if (script.startsWith("bun run ")) script = script.slice(8);
name = `Bun Task: ${name}`;
const terminals = getActiveTerminal(name);
if (terminals.length > 0) {
terminals[0].show();
terminals[0].sendText(`bun ${script}`);
terminals[0].sendText(`bun run ${script}`);
return;
}
const terminal = vscode.window.createTerminal({ name });
terminal.show();
terminal.sendText(`bun ${script}`);
terminal.sendText(`bun run ${script}`);
}),
);
}