From e4953f503c2d41e60aecf61d67678da6cfbc3ec4 Mon Sep 17 00:00:00 2001 From: Tyler Leonhardt Date: Thu, 19 Aug 2021 10:32:35 -0700 Subject: [PATCH] look at file extension instead of calling getModeIdByFilepathOrFirstLine and remove .txt from stdin files --- src/vs/platform/environment/node/stdin.ts | 2 +- .../services/textfile/common/textFileEditorModel.ts | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/vs/platform/environment/node/stdin.ts b/src/vs/platform/environment/node/stdin.ts index d5ab11b21ed..93c08e1d0b9 100644 --- a/src/vs/platform/environment/node/stdin.ts +++ b/src/vs/platform/environment/node/stdin.ts @@ -36,7 +36,7 @@ export function stdinDataListener(durationinMs: number): Promise { } export function getStdinFilePath(): string { - return paths.join(os.tmpdir(), `code-stdin-${Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 3)}.txt`); + return paths.join(os.tmpdir(), `code-stdin-${Math.random().toString(36).replace(/[^a-z]+/g, '').substr(0, 3)}`); } export async function readFromStdin(targetPath: string, verbose: boolean): Promise { diff --git a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts index 06804f1de11..e06d85815c2 100644 --- a/src/vs/workbench/services/textfile/common/textFileEditorModel.ts +++ b/src/vs/workbench/services/textfile/common/textFileEditorModel.ts @@ -605,10 +605,20 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil this.autoDetectLanguage(); } + private _resourceHasExtension: boolean | undefined; + private async getResourceHasExtension() { + if (this._resourceHasExtension !== undefined) { + return this._resourceHasExtension; + } + const path = await this.pathService.path; + this._resourceHasExtension = !!path.extname(this.resource.fsPath); + return this._resourceHasExtension; + } + protected override async autoDetectLanguage(): Promise { if ( this.resource.scheme === this.pathService.defaultUriScheme && // make sure to not detect language for non-user visible documents - !this.modeService.getModeIdByFilepathOrFirstLine(this.resource) // only run if a mode is not associated with this particular file + !await this.getResourceHasExtension() // only run if this particular file doesn't have an extension ) { return super.autoDetectLanguage(); }