diff --git a/src/features/DocumentFormatter.ts b/src/features/DocumentFormatter.ts index 716fb84dfa..1b99673caf 100644 --- a/src/features/DocumentFormatter.ts +++ b/src/features/DocumentFormatter.ts @@ -21,6 +21,7 @@ import { DocumentFormattingRequest, DocumentRangeFormattingParams, DocumentRangeFormattingRequest, + DocumentSelector, LanguageClient, RequestType, } from "vscode-languageclient"; @@ -317,16 +318,16 @@ export class DocumentFormatterFeature implements IFeature { private languageClient: LanguageClient; private documentFormattingEditProvider: PSDocumentFormattingEditProvider; - constructor(private logger: Logger) { + constructor(private logger: Logger, documentSelector: DocumentSelector) { this.documentFormattingEditProvider = new PSDocumentFormattingEditProvider(logger); this.formattingEditProvider = vscode.languages.registerDocumentFormattingEditProvider( - "powershell", + documentSelector, this.documentFormattingEditProvider); this.rangeFormattingEditProvider = vscode.languages.registerDocumentRangeFormattingEditProvider( - "powershell", + documentSelector, this.documentFormattingEditProvider); this.onTypeFormattingEditProvider = vscode.languages.registerOnTypeFormattingEditProvider( - "powershell", + documentSelector, this.documentFormattingEditProvider, this.firstTriggerCharacter, ...this.moreTriggerCharacters); diff --git a/src/main.ts b/src/main.ts index 169235db8b..8e40208624 100644 --- a/src/main.ts +++ b/src/main.ts @@ -6,6 +6,7 @@ import path = require("path"); import vscode = require("vscode"); +import { DocumentSelector } from "vscode-languageclient"; import { IFeature } from "./feature"; import { CodeActionsFeature } from "./features/CodeActions"; import { ConsoleFeature } from "./features/Console"; @@ -40,6 +41,11 @@ let logger: Logger; let sessionManager: SessionManager; let extensionFeatures: IFeature[] = []; +const documentSelector: DocumentSelector = [ + { language: "powershell", scheme: "file" }, + { language: "powershell", scheme: "untitled" }, +]; + export function activate(context: vscode.ExtensionContext): void { checkForUpdatedVersion(context); @@ -103,7 +109,7 @@ export function activate(context: vscode.ExtensionContext): void { sessionManager = new SessionManager( requiredEditorServicesVersion, - logger); + logger, documentSelector); // Create features extensionFeatures = [ @@ -119,7 +125,7 @@ export function activate(context: vscode.ExtensionContext): void { new SelectPSSARulesFeature(), new CodeActionsFeature(), new NewFileOrProjectFeature(), - new DocumentFormatterFeature(logger), + new DocumentFormatterFeature(logger, documentSelector), new RemoteFilesFeature(), new DebugSessionFeature(context, sessionManager), new PickPSHostProcessFeature(), diff --git a/src/session.ts b/src/session.ts index 9a944292a3..446adf8a89 100644 --- a/src/session.ts +++ b/src/session.ts @@ -17,7 +17,7 @@ import Settings = require("./settings"); import utils = require("./utils"); import { - CloseAction, ErrorAction, Executable, LanguageClient, LanguageClientOptions, + CloseAction, DocumentSelector, ErrorAction, Executable, LanguageClient, LanguageClientOptions, Middleware, NotificationType, RequestType, RequestType0, ResolveCodeLensSignature, RevealOutputChannelOn, StreamInfo } from "vscode-languageclient"; @@ -62,7 +62,8 @@ export class SessionManager implements Middleware { constructor( private requiredEditorServicesVersion: string, - private log: Logger) { + private log: Logger, + private documentSelector: DocumentSelector) { this.platformDetails = getPlatformDetails(); @@ -541,7 +542,7 @@ export class SessionManager implements Middleware { }; const clientOptions: LanguageClientOptions = { - documentSelector: [utils.PowerShellLanguageId], + documentSelector: this.documentSelector, synchronize: { configurationSection: utils.PowerShellLanguageId, // fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc')