Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ec15a0a

Browse files
Move readSessionFile and deleteSessionFile to process
As that's the only place they're used.
1 parent 842a93c commit ec15a0a

File tree

2 files changed

+68
-65
lines changed

2 files changed

+68
-65
lines changed

‎src/process.ts‎

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation.
22
// Licensed under the MIT License.
33

4+
import fs = require("fs");
45
import cp = require("child_process");
56
import * as semver from "semver";
67
import path = require("path");
@@ -100,7 +101,7 @@ export class PowerShellProcess {
100101
" PowerShell Editor Services args: " + startEditorServices);
101102

102103
// Make sure no old session file exists
103-
SessionManager.deleteSessionFile(this.sessionFilePath);
104+
awaitPowerShellProcess.deleteSessionFile(this.sessionFilePath);
104105

105106
// Launch PowerShell in the integrated terminal
106107
const terminalOptions: vscode.TerminalOptions = {
@@ -150,7 +151,7 @@ export class PowerShellProcess {
150151

151152
public dispose() {
152153
// Clean up the session file
153-
SessionManager.deleteSessionFile(this.sessionFilePath);
154+
PowerShellProcess.deleteSessionFile(this.sessionFilePath);
154155

155156
if (this.consoleCloseSubscription) {
156157
this.consoleCloseSubscription.dispose();
@@ -190,6 +191,20 @@ export class PowerShellProcess {
190191
return true;
191192
}
192193

194+
private static readSessionFile(sessionFilePath: vscode.Uri): IEditorServicesSessionDetails {
195+
// TODO: Use vscode.workspace.fs.readFile instead of fs.readFileSync.
196+
const fileContents = fs.readFileSync(sessionFilePath.fsPath, "utf-8");
197+
return JSON.parse(fileContents);
198+
}
199+
200+
private static async deleteSessionFile(sessionFilePath: vscode.Uri) {
201+
try {
202+
await vscode.workspace.fs.delete(sessionFilePath);
203+
} catch (e) {
204+
// TODO: Be more specific about what we're catching
205+
}
206+
}
207+
193208
private async waitForSessionFile(): Promise<IEditorServicesSessionDetails> {
194209
// Determine how many tries by dividing by 2000 thus checking every 2 seconds.
195210
const numOfTries = this.sessionSettings.developer.waitForSessionFileTimeoutSeconds / 2;
@@ -199,8 +214,8 @@ export class PowerShellProcess {
199214
for (let i = numOfTries; i > 0; i--) {
200215
if (utils.checkIfFileExists(this.sessionFilePath.fsPath)) {
201216
this.log.write("Session file found");
202-
const sessionDetails = SessionManager.readSessionFile(this.sessionFilePath);
203-
SessionManager.deleteSessionFile(this.sessionFilePath);
217+
const sessionDetails = PowerShellProcess.readSessionFile(this.sessionFilePath);
218+
PowerShellProcess.deleteSessionFile(this.sessionFilePath);
204219
return sessionDetails;
205220
}
206221

‎src/session.ts‎

Lines changed: 49 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,15 @@ import utils = require("./utils");
1616
import {
1717
CloseAction, DocumentSelector, ErrorAction, LanguageClientOptions,
1818
Middleware, NotificationType, RequestType0,
19-
ResolveCodeLensSignature, RevealOutputChannelOn } from "vscode-languageclient";
19+
ResolveCodeLensSignature, RevealOutputChannelOn
20+
} from "vscode-languageclient";
2021
import { LanguageClient, StreamInfo } from "vscode-languageclient/node";
2122

2223
import { GitHubReleaseInformation, InvokePowerShellUpdateCheck } from "./features/UpdatePowerShell";
2324
import {
2425
getPlatformDetails, IPlatformDetails, IPowerShellExeDetails,
25-
OperatingSystem, PowerShellExeFinder } from "./platform";
26+
OperatingSystem, PowerShellExeFinder
27+
} from "./platform";
2628
import { LanguageClientConsumer } from "./languageClientConsumer";
2729

2830
export enum SessionStatus {
@@ -285,20 +287,6 @@ export class SessionManager implements Middleware {
285287
return vscode.Uri.joinPath(this.sessionsFolder, "PSES-VSCode-" + process.env.VSCODE_PID + "-" + uniqueId + ".json");
286288
}
287289

288-
public static readSessionFile(sessionFilePath: vscode.Uri): IEditorServicesSessionDetails {
289-
// TODO: Use vscode.workspace.fs.readFile instead of fs.readFileSync.
290-
const fileContents = fs.readFileSync(sessionFilePath.fsPath, "utf-8");
291-
return JSON.parse(fileContents);
292-
}
293-
294-
public static async deleteSessionFile(sessionFilePath: vscode.Uri) {
295-
try {
296-
await vscode.workspace.fs.delete(sessionFilePath);
297-
} catch (e) {
298-
// TODO: Be more specific about what we're catching
299-
}
300-
}
301-
302290
public createDebugSessionProcess(sessionSettings: Settings.ISettings): PowerShellProcess {
303291

304292
// NOTE: We only support one temporary integrated console at a time. To
@@ -335,7 +323,7 @@ export class SessionManager implements Middleware {
335323
}
336324

337325
public async waitUntilStarted(): Promise<void> {
338-
while(!this.started) {
326+
while(!this.started) {
339327
await utils.sleep(300);
340328
}
341329
}
@@ -346,43 +334,43 @@ export class SessionManager implements Middleware {
346334
codeLens: vscode.CodeLens,
347335
token: vscode.CancellationToken,
348336
next: ResolveCodeLensSignature): vscode.ProviderResult<vscode.CodeLens> {
349-
const resolvedCodeLens = next(codeLens, token);
350-
const resolveFunc =
351-
(codeLensToFix: vscode.CodeLens): vscode.CodeLens => {
352-
if (codeLensToFix.command?.command === "editor.action.showReferences") {
353-
const oldArgs = codeLensToFix.command.arguments;
354-
355-
// Our JSON objects don't get handled correctly by
356-
// VS Code's built in editor.action.showReferences
357-
// command so we need to convert them into the
358-
// appropriate types to send them as command
359-
// arguments.
360-
361-
codeLensToFix.command.arguments = [
362-
vscode.Uri.parse(oldArgs[0]),
363-
new vscode.Position(oldArgs[1].line, oldArgs[1].character),
364-
oldArgs[2].map((position) => {
365-
return new vscode.Location(
366-
vscode.Uri.parse(position.uri),
367-
new vscode.Range(
368-
position.range.start.line,
369-
position.range.start.character,
370-
position.range.end.line,
371-
position.range.end.character));
372-
}),
373-
];
374-
}
337+
const resolvedCodeLens = next(codeLens, token);
338+
const resolveFunc =
339+
(codeLensToFix: vscode.CodeLens): vscode.CodeLens => {
340+
if (codeLensToFix.command?.command === "editor.action.showReferences") {
341+
const oldArgs = codeLensToFix.command.arguments;
342+
343+
// Our JSON objects don't get handled correctly by
344+
// VS Code's built in editor.action.showReferences
345+
// command so we need to convert them into the
346+
// appropriate types to send them as command
347+
// arguments.
348+
349+
codeLensToFix.command.arguments = [
350+
vscode.Uri.parse(oldArgs[0]),
351+
new vscode.Position(oldArgs[1].line, oldArgs[1].character),
352+
oldArgs[2].map((position) => {
353+
return new vscode.Location(
354+
vscode.Uri.parse(position.uri),
355+
new vscode.Range(
356+
position.range.start.line,
357+
position.range.start.character,
358+
position.range.end.line,
359+
position.range.end.character));
360+
}),
361+
];
362+
}
375363

376-
return codeLensToFix;
377-
};
364+
return codeLensToFix;
365+
};
378366

379-
if ((resolvedCodeLens as Thenable<vscode.CodeLens>).then) {
380-
return (resolvedCodeLens as Thenable<vscode.CodeLens>).then(resolveFunc);
381-
} else if (resolvedCodeLens as vscode.CodeLens) {
382-
return resolveFunc(resolvedCodeLens as vscode.CodeLens);
383-
}
367+
if ((resolvedCodeLens as Thenable<vscode.CodeLens>).then) {
368+
return (resolvedCodeLens as Thenable<vscode.CodeLens>).then(resolveFunc);
369+
} else if (resolvedCodeLens as vscode.CodeLens) {
370+
return resolveFunc(resolvedCodeLens as vscode.CodeLens);
371+
}
384372

385-
return resolvedCodeLens;
373+
return resolvedCodeLens;
386374
}
387375

388376
// Move old setting codeFormatting.whitespaceAroundPipe to new setting codeFormatting.addWhitespaceAroundPipe
@@ -438,9 +426,9 @@ export class SessionManager implements Middleware {
438426
this.sessionSettings.cwd.toLowerCase() ||
439427
settings.powerShellDefaultVersion.toLowerCase() !==
440428
this.sessionSettings.powerShellDefaultVersion.toLowerCase() ||
441-
settings.developer.editorServicesLogLevel.toLowerCase() !==
429+
settings.developer.editorServicesLogLevel.toLowerCase() !==
442430
this.sessionSettings.developer.editorServicesLogLevel.toLowerCase() ||
443-
settings.developer.bundledModulesPath.toLowerCase() !==
431+
settings.developer.bundledModulesPath.toLowerCase() !==
444432
this.sessionSettings.developer.bundledModulesPath.toLowerCase() ||
445433
settings.integratedConsole.useLegacyReadLine !==
446434
this.sessionSettings.integratedConsole.useLegacyReadLine)) {
@@ -449,9 +437,9 @@ export class SessionManager implements Middleware {
449437
"The PowerShell runtime configuration has changed, would you like to start a new session?",
450438
"Yes", "No");
451439

452-
if (response === "Yes") {
453-
await this.restartSession();
454-
}
440+
if (response === "Yes") {
441+
await this.restartSession();
442+
}
455443
}
456444
}
457445

@@ -565,7 +553,7 @@ export class SessionManager implements Middleware {
565553
"connect",
566554
() => {
567555
this.log.write("Language service connected.");
568-
resolve({writer: socket, reader: socket});
556+
resolve({writer: socket, reader: socket});
569557
});
570558
});
571559
};
@@ -574,7 +562,7 @@ export class SessionManager implements Middleware {
574562
documentSelector: this.documentSelector,
575563
synchronize: {
576564
// backend uses "files" and "search" to ignore references.
577-
configurationSection: [utils.PowerShellLanguageId, "files", "search"],
565+
configurationSection: [utils.PowerShellLanguageId, "files", "search"],
578566
// fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc')
579567
},
580568
// NOTE: Some settings are only applicable on startup, so we send them during initialization.
@@ -817,8 +805,8 @@ export class SessionManager implements Middleware {
817805
case SessionStatus.NeverStarted:
818806
case SessionStatus.Stopping:
819807
const currentPowerShellExe =
820-
availablePowerShellExes
821-
.find((item) => item.displayName.toLowerCase() === this.PowerShellExeDetails.displayName.toLowerCase());
808+
availablePowerShellExes
809+
.find((item) => item.displayName.toLowerCase() === this.PowerShellExeDetails.displayName.toLowerCase());
822810

823811
const powerShellSessionName =
824812
currentPowerShellExe ?
@@ -885,7 +873,7 @@ class SessionMenuItem implements vscode.QuickPickItem {
885873
constructor(
886874
public readonly label: string,
887875
// tslint:disable-next-line:no-empty
888-
public readonly callback: () => void = () => {}) {
876+
public readonly callback: () => void = () => {}) {
889877
}
890878
}
891879

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /