11import path from "path" ;
22import * as vscode from "vscode" ;
33import * as main from "./main" ;
4- import * as shared from "./language/Shared" ;
54
65function isAutoDetectEnabled ( ) : boolean {
76 return main . config . get < boolean > ( "kvAutoDetect.enabled" , false ) ;
87}
98
10- function isAutoDetectEnabledOnlyInWorkspaces ( ) : boolean {
11- return main . config . get < boolean > ( "kvAutoDetect.onlyInSourceEngineWorkspaces" , true ) ;
12- }
13-
14- function getSourceEngineWorkspaces ( ) : string [ ] {
15- return main . config . get < string [ ] > ( "sourceEngineWorkspaces" , [ ] ) ;
16- }
17-
18-
199type DetectableLanguageId = "keyvalue3" | "soundscript" | "captions" ;
10+
2011interface CommonFileName {
2112 regex : RegExp ;
2213 languageId : DetectableLanguageId ;
@@ -93,15 +84,6 @@ function detectKeyvalueFile(editor: vscode.TextEditor, context: vscode.Extension
9384}
9485
9586function getPotentialKvFileLanguageId ( document : vscode . TextDocument ) : DetectableLanguageId | undefined {
96- if ( isAutoDetectEnabledOnlyInWorkspaces ( ) ) {
97-
98- if ( ! isDocumentInSourceEngineWorkspace ( document ) ) {
99- main . debugOutput . appendLine ( `Auto detect is enabled only in source engine workspaces, but the document (${ document . uri . fsPath } ) is not in a source engine workspace.` ) ;
100- return undefined ;
101- }
102-
103- }
104-
10587 const documentFileName = path . basename ( document . uri . fsPath ) ;
10688
10789 main . debugOutput . appendLine ( `Auto detect is enabled. Checking if filename (${ documentFileName } ) is in list of common kv file names.` ) ;
@@ -113,29 +95,3 @@ function getPotentialKvFileLanguageId(document: vscode.TextDocument): Detectable
11395 main . debugOutput . appendLine ( `! File (${ document . uri . fsPath } ) has a common file name and is associated with LanguageId: ${ match . languageId } ` ) ;
11496 return match . languageId ;
11597}
116-
117- function isDocumentInSourceEngineWorkspace ( document : vscode . TextDocument ) : boolean {
118- let fileUri : string = document . uri . fsPath ;
119- let sourceEngineWorkspaces : string [ ] = getSourceEngineWorkspaces ( ) ;
120-
121- // Make paths lower case on windows
122- if ( process . platform === "win32" ) {
123- fileUri = fileUri . toLowerCase ( ) ;
124- sourceEngineWorkspaces = sourceEngineWorkspaces . map ( ( workspace ) => workspace . toLowerCase ( ) ) ;
125- }
126-
127- main . debugOutput . appendLine ( `Checking if file (${ fileUri } ) is in any source engine workspace.` ) ;
128-
129- for ( const workspace of sourceEngineWorkspaces ) {
130- main . debugOutput . appendLine ( `- Checking if file (${ fileUri } ) is in workspace (${ workspace } )` ) ;
131- if ( fileUri . startsWith ( workspace ) ) {
132- main . debugOutput . appendLine ( `! File (${ fileUri } ) is in workspace (${ workspace } )` ) ;
133- return true ;
134- }
135- }
136-
137- main . debugOutput . appendLine ( `! File (${ fileUri } ) is not in any source engine workspace.` ) ;
138-
139- return false ;
140- }
141-
0 commit comments