look at file extension instead of calling getModeIdByFilepathOrFirstLine and remove .txt from stdin files
This commit is contained in:
parent
cac895a654
commit
e4953f503c
2 changed files with 12 additions and 2 deletions
|
@ -36,7 +36,7 @@ export function stdinDataListener(durationinMs: number): Promise<boolean> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getStdinFilePath(): string {
|
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> {
|
export async function readFromStdin(targetPath: string, verbose: boolean): Promise<void> {
|
||||||
|
|
|
@ -605,10 +605,20 @@ export class TextFileEditorModel extends BaseTextEditorModel implements ITextFil
|
||||||
this.autoDetectLanguage();
|
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> {
|
protected override async autoDetectLanguage(): Promise<void> {
|
||||||
if (
|
if (
|
||||||
this.resource.scheme === this.pathService.defaultUriScheme && // make sure to not detect language for non-user visible documents
|
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();
|
return super.autoDetectLanguage();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue