Skip to content

Commit 88d371e

Browse files
committed
Add option to disable keyvalue file detection
1 parent 16f5faf commit 88d371e

File tree

2 files changed

+29
-9
lines changed

2 files changed

+29
-9
lines changed

package.json

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,21 @@
382382
"type": "boolean",
383383
"default": true,
384384
"description": "Warn when the file of a texture property can't be found"
385+
},
386+
"sourceEngine.detectKeyvalueFiles.enabled": {
387+
"type": "boolean",
388+
"default": true,
389+
"description": "Automatically use keyvalue file format for common file names like gameinfo.txt, subtitles_english.txt..."
390+
},
391+
"sourceEngine.detectKeyvalueFiles.customRules": {
392+
"type": "array",
393+
"default": [],
394+
"description": "Define custom rules to detect keyvalue files based on the file name"
395+
},
396+
"sourceEngine.detectKeyvalueFiles.onlyUseCustomRules": {
397+
"type": "boolean",
398+
"default": false,
399+
"description": "Disables all the common file name rules that come with the extension. Useful if some standard rule is causing problems and you would rather define them yourself"
385400
}
386401
}
387402
},

src/KvFileDetection.ts

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,19 +47,24 @@ function onChangeEditor(document: vscode.TextDocument): void {
4747

4848
function detectKeyvalueFile(document: vscode.TextDocument): void {
4949

50+
const enabled = main.config.get("detectKeyvalueFiles.enabled");
51+
if(!enabled) {
52+
return;
53+
}
54+
5055
main.debugOutput.appendLine("File has language id: " + document.languageId);
51-
if(document.languageId === "plaintext") {
52-
main.debugOutput.appendLine(`Potential kv file opened (${document.uri.fsPath})`);
56+
if(document.languageId !== "plaintext") return;
5357

54-
const langId = getPotentialKvFileLanguageId(document);
55-
if(langId === undefined) {
56-
main.debugOutput.appendLine(`Not changing document language of (${document.uri.fsPath})`);
57-
return;
58-
}
58+
main.debugOutput.appendLine(`Potential kv file opened (${document.uri.fsPath})`);
5959

60-
main.debugOutput.appendLine(`Changing document language of (${document.uri.fsPath}) to keyvalue`);
61-
vscode.languages.setTextDocumentLanguage(document, langId);
60+
const langId = getPotentialKvFileLanguageId(document);
61+
if(langId === undefined) {
62+
main.debugOutput.appendLine(`Not changing document language of (${document.uri.fsPath})`);
63+
return;
6264
}
65+
66+
main.debugOutput.appendLine(`Changing document language of (${document.uri.fsPath}) to keyvalue`);
67+
vscode.languages.setTextDocumentLanguage(document, langId);
6368
}
6469

6570
function getPotentialKvFileLanguageId(document: vscode.TextDocument): DetectableLanguageId | undefined {

0 commit comments

Comments
 (0)