Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Discussion] [Live Share] Restrict language services to local files #1264

Merged
merged 4 commits into from
Apr 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/features/DocumentFormatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
DocumentFormattingRequest,
DocumentRangeFormattingParams,
DocumentRangeFormattingRequest,
DocumentSelector,
LanguageClient,
RequestType,
} from "vscode-languageclient";
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 8 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -103,7 +109,7 @@ export function activate(context: vscode.ExtensionContext): void {
sessionManager =
new SessionManager(
requiredEditorServicesVersion,
logger);
logger, documentSelector);

// Create features
extensionFeatures = [
Expand All @@ -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(),
Expand Down
7 changes: 4 additions & 3 deletions src/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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')
Expand Down