Skip to content

Commit 9fb499c

Browse files
authored
infer language of preview files from their uri (microsoft#184699)
microsoft/vscode-copilot#350
1 parent 4d7056f commit 9fb499c

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/vs/workbench/contrib/inlineChat/browser/inlineChatLivePreviewWidget.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import { FileKind } from 'vs/platform/files/common/files';
3131
import { IModelService } from 'vs/editor/common/services/model';
3232
import { EditOperation } from 'vs/editor/common/core/editOperation';
3333
import { Session } from 'vs/workbench/contrib/inlineChat/browser/inlineChatSession';
34+
import { ILanguageService } from 'vs/editor/common/languages/language';
3435

3536
export class InlineChatLivePreviewWidget extends ZoneWidget {
3637

@@ -349,6 +350,7 @@ export class InlineChatFileCreatePreviewWidget extends ZoneWidget {
349350
constructor(
350351
parentEditor: ICodeEditor,
351352
@IInstantiationService instaService: IInstantiationService,
353+
@ILanguageService private readonly _languageService: ILanguageService,
352354
@IModelService private readonly _modelService: IModelService,
353355
@IThemeService themeService: IThemeService,
354356

@@ -401,8 +403,8 @@ export class InlineChatFileCreatePreviewWidget extends ZoneWidget {
401403
showCreation(where: Range, uri: URI, edits: TextEdit[]): void {
402404

403405
this._title.element.setFile(uri, { fileKind: FileKind.FILE });
404-
405-
const model = this._modelService.createModel('', null, undefined, true);
406+
const langSelection = this._languageService.createByFilepathOrFirstLine(uri, undefined);
407+
const model = this._modelService.createModel('', langSelection, undefined, true);
406408
model.applyEdits(edits.map(edit => EditOperation.replace(Range.lift(edit.range), edit.text)));
407409
this._previewModel.value = model;
408410
this._previewEditor.setModel(model);

0 commit comments

Comments
 (0)