Skip to content

Commit

Permalink
Add selectTeamFortress2Folder command
Browse files Browse the repository at this point in the history
  • Loading branch information
cooolbros authored Feb 22, 2025
1 parent a152365 commit 9213e8f
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 16 deletions.
3 changes: 2 additions & 1 deletion apps/extension/browser/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Client, VSCodeVDFLanguageIDSchema, VSCodeVDFLanguageNameSchema, type VS
import { copyKeyValuePath } from "client/commands/copyKeyValuePath"
import { importPopfileTemplates } from "client/commands/importPopfileTemplates"
import { JSONToVDF } from "client/commands/JSONToVDF"
import { selectTeamFortress2Folder } from "client/commands/selectTeamFortress2Folder"
import { showReferences } from "client/commands/showReferences"
import { VDFToJSON } from "client/commands/VDFToJSON"
import { onDidChangeActiveTextEditor } from "client/decorations"
Expand All @@ -17,7 +18,7 @@ export function activate(context: ExtensionContext): void {
// https://code.visualstudio.com/api/references/vscode-api

// Commands

context.subscriptions.push(commands.registerCommand("vscode-vdf.selectTeamFortress2Folder", selectTeamFortress2Folder))
context.subscriptions.push(commands.registerTextEditorCommand("vscode-vdf.copyKeyValuePath", copyKeyValuePath))
context.subscriptions.push(commands.registerTextEditorCommand("vscode-vdf.importPopfileTemplates", importPopfileTemplates))
context.subscriptions.push(commands.registerTextEditorCommand("vscode-vdf.JSONToVDF", JSONToVDF))
Expand Down
24 changes: 11 additions & 13 deletions apps/extension/desktop/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { VDFToJSON } from "client/commands/VDFToJSON"
import { copyKeyValuePath } from "client/commands/copyKeyValuePath"
import { extractVPKFileToWorkspace } from "client/commands/extractVPKFileToWorkspace"
import { importPopfileTemplates } from "client/commands/importPopfileTemplates"
import { selectTeamFortress2Folder } from "client/commands/selectTeamFortress2Folder"
import { showReferences } from "client/commands/showReferences"
import { onDidChangeActiveTextEditor } from "client/decorations"
import { join } from "path"
Expand All @@ -20,7 +21,7 @@ export function activate(context: ExtensionContext): void {
// https://code.visualstudio.com/api/references/vscode-api

// Commands

context.subscriptions.push(commands.registerCommand("vscode-vdf.selectTeamFortress2Folder", selectTeamFortress2Folder))
context.subscriptions.push(commands.registerTextEditorCommand("vscode-vdf.copyKeyValuePath", copyKeyValuePath))
context.subscriptions.push(commands.registerTextEditorCommand("vscode-vdf.extractVPKFileToWorkspace", extractVPKFileToWorkspace))
context.subscriptions.push(commands.registerTextEditorCommand("vscode-vdf.importPopfileTemplates", importPopfileTemplates))
Expand Down Expand Up @@ -53,6 +54,13 @@ export function activate(context: ExtensionContext): void {
const serverModule = context.asAbsolutePath(join("apps/extension/desktop/servers/dist", `${languageId}.js`))
const name = VSCodeVDFLanguageNameSchema.shape[languageId].value

const options = {
execArgv: [
"--nolazy",
`--inspect=${6000 + Object.keys(VSCodeVDFLanguageNameSchema.shape).indexOf(languageId)}`
]
}

const client = languageClients[languageId] = new Client<LanguageClient>(
languageClients,
startServer,
Expand All @@ -65,23 +73,13 @@ export function activate(context: ExtensionContext): void {
module: serverModule,
transport: TransportKind.ipc,
...(process.env.NODE_ENV != "production" && {
options: {
execArgv: [
"--nolazy",
`--inspect=${6000 + Object.keys(VSCodeVDFLanguageNameSchema.shape).indexOf(languageId)}`
]
}
options: options
})
},
debug: {
module: serverModule,
transport: TransportKind.ipc,
options: {
execArgv: [
"--nolazy",
"--inspect=6009"
]
}
options: options
}
} satisfies ServerOptions,
{
Expand Down
12 changes: 10 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@
"title": "Restart VMT Language Server",
"command": "vscode-vdf.restartVMTLanguageServer"
},
{
"category": "VDF",
"command": "vscode-vdf.selectTeamFortress2Folder",
"title": "Select Team Fortress 2 folder"
},
{
"category": "VDF",
"title": "Show References",
Expand Down Expand Up @@ -112,8 +117,11 @@
},
"vscode-vdf.teamFortress2Folder": {
"type": "string",
"markdownDescription": "Path to `Team Fortress 2` folder",
"default": "C:/Program Files (x86)/Steam/steamapps/common/Team Fortress 2"
"markdownDescription": "Path to `Team Fortress 2` folder.\n\n[Select Folder](command:vscode-vdf.selectTeamFortress2Folder)",
"default": "C:/Program Files (x86)/Steam/steamapps/common/Team Fortress 2",
"examples": [
"~/.local/share/Steam/steamapps/common/Team Fortress 2"
]
},
"vscode-vdf.updateDiagnosticsEvent": {
"type": "string",
Expand Down
25 changes: 25 additions & 0 deletions packages/client/src/commands/selectTeamFortress2Folder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { commands, Uri, window, workspace } from "vscode"

export async function selectTeamFortress2Folder() {
const result = await window.showOpenDialog({
canSelectFiles: false,
canSelectFolders: true,
canSelectMany: false,
})

if (result && result.length) {
const uri = result[0]

const exists = await workspace.fs.stat(Uri.joinPath(uri, "tf/gameinfo.txt")).then(() => true, () => false)
if (!exists) {
window.showErrorMessage(`Invalid Team Fortress 2 folder: "${uri.fsPath}"`)
return
}

const path = uri.fsPath.replaceAll("\\", "/")
workspace.getConfiguration("vscode-vdf").update("teamFortress2Folder", path, true)

// Open settings UI to unfocus "Select Folder" link and refresh UI
commands.executeCommand("workbench.action.openSettings2")
}
}

0 comments on commit 9213e8f

Please sign in to comment.