look at file extension instead of calling getModeIdByFilepathOrFirstLine and remove .txt from stdin files

This commit is contained in:
Tyler Leonhardt 2021-08-19 10:32:35 -07:00
parent cac895a654
commit e4953f503c
No known key found for this signature in database
GPG key ID: 1BC2B6244363E77E
2 changed files with 12 additions and 2 deletions

View file

@ -36,7 +36,7 @@ export function stdinDataListener(durationinMs: number): Promise<boolean> {
}
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<void> {

View file

@ -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<void> {
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();
}