Skip to content

Commit 14c7d4a

Browse files
committed
Move readSessionFile and deleteSessionFile to process
As that's the only place they're used.
1 parent 8b27d86 commit 14c7d4a

File tree

2 files changed

+68
-65
lines changed

2 files changed

+68
-65
lines changed

src/process.ts

+19-4
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+
await PowerShellProcess.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

+49-61
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 {
@@ -287,20 +289,6 @@ export class SessionManager implements Middleware {
287289
return vscode.Uri.joinPath(this.sessionsFolder, "PSES-VSCode-" + process.env.VSCODE_PID + "-" + uniqueId + ".json");
288290
}
289291

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

306294
// NOTE: We only support one temporary integrated console at a time. To
@@ -337,7 +325,7 @@ export class SessionManager implements Middleware {
337325
}
338326

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

378-
return codeLensToFix;
379-
};
366+
return codeLensToFix;
367+
};
380368

381-
if ((resolvedCodeLens as Thenable<vscode.CodeLens>).then) {
382-
return (resolvedCodeLens as Thenable<vscode.CodeLens>).then(resolveFunc);
383-
} else if (resolvedCodeLens as vscode.CodeLens) {
384-
return resolveFunc(resolvedCodeLens as vscode.CodeLens);
385-
}
369+
if ((resolvedCodeLens as Thenable<vscode.CodeLens>).then) {
370+
return (resolvedCodeLens as Thenable<vscode.CodeLens>).then(resolveFunc);
371+
} else if (resolvedCodeLens as vscode.CodeLens) {
372+
return resolveFunc(resolvedCodeLens as vscode.CodeLens);
373+
}
386374

387-
return resolvedCodeLens;
375+
return resolvedCodeLens;
388376
}
389377

390378
// Move old setting codeFormatting.whitespaceAroundPipe to new setting codeFormatting.addWhitespaceAroundPipe
@@ -440,9 +428,9 @@ export class SessionManager implements Middleware {
440428
this.sessionSettings.cwd.toLowerCase() ||
441429
settings.powerShellDefaultVersion.toLowerCase() !==
442430
this.sessionSettings.powerShellDefaultVersion.toLowerCase() ||
443-
settings.developer.editorServicesLogLevel.toLowerCase() !==
431+
settings.developer.editorServicesLogLevel.toLowerCase() !==
444432
this.sessionSettings.developer.editorServicesLogLevel.toLowerCase() ||
445-
settings.developer.bundledModulesPath.toLowerCase() !==
433+
settings.developer.bundledModulesPath.toLowerCase() !==
446434
this.sessionSettings.developer.bundledModulesPath.toLowerCase() ||
447435
settings.integratedConsole.useLegacyReadLine !==
448436
this.sessionSettings.integratedConsole.useLegacyReadLine)) {
@@ -451,9 +439,9 @@ export class SessionManager implements Middleware {
451439
"The PowerShell runtime configuration has changed, would you like to start a new session?",
452440
"Yes", "No");
453441

454-
if (response === "Yes") {
455-
await this.restartSession();
456-
}
442+
if (response === "Yes") {
443+
await this.restartSession();
444+
}
457445
}
458446
}
459447

@@ -567,7 +555,7 @@ export class SessionManager implements Middleware {
567555
"connect",
568556
() => {
569557
this.log.write("Language service connected.");
570-
resolve({writer: socket, reader: socket});
558+
resolve({ writer: socket, reader: socket });
571559
});
572560
});
573561
};
@@ -576,7 +564,7 @@ export class SessionManager implements Middleware {
576564
documentSelector: this.documentSelector,
577565
synchronize: {
578566
// backend uses "files" and "search" to ignore references.
579-
configurationSection: [ utils.PowerShellLanguageId, "files", "search" ],
567+
configurationSection: [utils.PowerShellLanguageId, "files", "search"],
580568
// fileEvents: vscode.workspace.createFileSystemWatcher('**/.eslintrc')
581569
},
582570
// NOTE: Some settings are only applicable on startup, so we send them during initialization.
@@ -819,8 +807,8 @@ export class SessionManager implements Middleware {
819807
case SessionStatus.NeverStarted:
820808
case SessionStatus.Stopping:
821809
const currentPowerShellExe =
822-
availablePowerShellExes
823-
.find((item) => item.displayName.toLowerCase() === this.PowerShellExeDetails.displayName.toLowerCase());
810+
availablePowerShellExes
811+
.find((item) => item.displayName.toLowerCase() === this.PowerShellExeDetails.displayName.toLowerCase());
824812

825813
const powerShellSessionName =
826814
currentPowerShellExe ?
@@ -887,7 +875,7 @@ class SessionMenuItem implements vscode.QuickPickItem {
887875
constructor(
888876
public readonly label: string,
889877
// tslint:disable-next-line:no-empty
890-
public readonly callback: () => void = () => {}) {
878+
public readonly callback: () => void = () => { }) {
891879
}
892880
}
893881

0 commit comments

Comments
 (0)