Skip to content

Commit b0add25

Browse files
committed
feat: new untitled editor command with preselected lang options e.g. ['2:typescript']
1 parent 794ad3a commit b0add25

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

package.json

+12
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,10 @@
315315
{
316316
"command": "showTrackedPositionsStack",
317317
"title": "Show Tracked Positions Stack"
318+
},
319+
{
320+
"command": "newUntitledEditor",
321+
"title": "New Untitled Editor"
318322
}
319323
],
320324
"configuration": {
@@ -572,6 +576,14 @@
572576
"trackDocumentPositions.debounce": {
573577
"type": "number",
574578
"default": 1000
579+
},
580+
"newUntitledEditor.suggestLanguages": {
581+
"type": "array",
582+
"uniqueItems": true,
583+
"items": {
584+
"type": "string"
585+
},
586+
"default": []
575587
}
576588
}
577589
},

src/features/debugRememberedConfiguration.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default () => {
1616
const getName = async () => {
1717
const [lastConfigName, pinned] = extensionCtx.workspaceState.get('debugRememberedConfiguration', ['', false] as State)
1818
const config = await vscode.workspace.fs.readFile(Utils.joinPath(workspace.uri, '.vscode/launch.json')).then(b => jsoncParser.parse(b.toString()))
19-
const configNames: string[] = [config.configurations, config.compounds].filter(Boolean).flatMap((configs: any) => configs.map(c => c.name))
19+
const configNames: string[] = [config.compounds, config.configurations].filter(Boolean).flatMap((configs: any) => configs.map(c => c.name))
2020
if (showSelector) {
2121
const pinButton = {
2222
tooltip: 'Pin Choice',
@@ -34,7 +34,7 @@ export default () => {
3434
? [
3535
{
3636
tooltip: 'Unpin Choice',
37-
iconPath: new vscode.ThemeIcon('remove-close'),
37+
iconPath: new vscode.ThemeIcon('timeline-unpin'),
3838
},
3939
]
4040
: [],

src/features/newUntitledEditor.ts

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as vscode from 'vscode'
2+
import { showQuickPick } from '@zardoy/vscode-utils/build/quickPick'
3+
import { getExtensionSetting, registerExtensionCommand } from 'vscode-framework'
4+
5+
// opinionated untitled editors creation
6+
export default () => {
7+
registerExtensionCommand('newUntitledEditor', async () => {
8+
const selected = await showQuickPick(getExtensionSetting('newUntitledEditor.suggestLanguages').map(x => ({ label: x, value: x })))
9+
if (!selected) return
10+
// open untitled editor with lang
11+
const doc = await vscode.workspace.openTextDocument({ language: selected.includes(':') ? selected.slice(selected.indexOf(':') + 1) : selected })
12+
await vscode.window.showTextDocument(doc)
13+
})
14+
}

0 commit comments

Comments
 (0)