-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,5 @@ module.exports = { | |
tabWidth: 4, | ||
useTabs: false, | ||
singleQuote: false, | ||
max_line_length: 100, | ||
printWidth: 100, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import * as vscode from "vscode"; | ||
|
||
const defaultConfig = `// Edit the default glimpse menu using javascript. | ||
module.exports = function editConfig(menu) { | ||
return menu; | ||
}`; | ||
|
||
export async function glimpseConfigure(context: vscode.ExtensionContext) { | ||
try { | ||
const storageUri = context.globalStorageUri; | ||
await createDirIfDoesntExist(storageUri); | ||
const configPath = vscode.Uri.joinPath(storageUri, "config.js"); | ||
await openConfig(configPath); | ||
} catch (err) { | ||
console.error("Failed to run Glimpse configure", err); | ||
} | ||
} | ||
|
||
async function createDirIfDoesntExist(dir: vscode.Uri) { | ||
try { | ||
// if dir doesn't exist, this will throw an error | ||
await vscode.workspace.fs.stat(dir); | ||
} catch (err) { | ||
await vscode.workspace.fs.createDirectory(dir); | ||
} | ||
} | ||
|
||
async function createFileIfDoesntExist(file: vscode.Uri, content: string) { | ||
try { | ||
// if file doesn't exist, this will throw an error | ||
await vscode.workspace.fs.stat(file); | ||
console.log("config file already exists"); | ||
} catch (err) { | ||
console.log("creating file", file); | ||
await vscode.workspace.fs.writeFile(file, Buffer.from(content)); | ||
// wait a while so that we avoid the error "file not found" in vscode | ||
await sleep(1000); | ||
} | ||
} | ||
|
||
function sleep(ms: number) { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
|
||
async function openConfig(configUri: vscode.Uri) { | ||
await createFileIfDoesntExist(configUri, defaultConfig); | ||
// open the file in the editor | ||
await vscode.commands.executeCommand("vscode.open", configUri); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,4 +20,5 @@ async function main() { | |
} | ||
} | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-floating-promises | ||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters