Skip to content

Commit 33e5599

Browse files
committed
Fix #11: Add script analysis settings
This change rearranges the current extension settings and adds a new one that allows the user to turn off real-time script analysis. The new setting organization will make it easier to add new settings to these areas in the future without having the user go rename their existing settings.
1 parent 0042484 commit 33e5599

File tree

4 files changed

+64
-45
lines changed

4 files changed

+64
-45
lines changed

package.json

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"Debuggers",
1414
"Linters"
1515
],
16-
"icon": "images/PowerShell_icon.png",
16+
"icon": "images/PowerShell_icon.png",
1717
"galleryBanner": {
1818
"color": "#ACD1EC",
1919
"theme": "light"
@@ -63,7 +63,7 @@
6363
"language": "powershell",
6464
"path": "./snippets/PowerShell.json"
6565
}
66-
],
66+
],
6767
"debuggers": [
6868
{
6969
"type": "PowerShell",
@@ -75,20 +75,20 @@
7575
"type": "object",
7676
"title": "PowerShell Configuration",
7777
"properties": {
78-
"PowerShell.editorServicesHostPath": {
78+
"powershell.scriptAnalysis.enable": {
79+
"type": "boolean",
80+
"default": true,
81+
"description": "Enables real-time script analysis using PowerShell Script Analyzer."
82+
},
83+
"powershell.developer.editorServicesHostPath": {
7984
"type": "string",
8085
"default": "../bin/Microsoft.PowerShell.EditorServices.Host.exe",
8186
"description": "Specifies the path to the PowerShell Editor Services host executable."
8287
},
83-
"PowerShell.waitForDebugger": {
88+
"powershell.developer.editorServicesWaitForDebugger": {
8489
"type": "boolean",
8590
"default": false,
8691
"description": "Launches the language service with the /waitForDebugger flag to force it to wait for a .NET debugger to attach before proceeding."
87-
},
88-
"PowerShell.enableLogging": {
89-
"type": "boolean",
90-
"default": true,
91-
"description": "Enables diagnostic logging for the extension."
9292
}
9393
}
9494
}

src/features/configuration.ts

-27
This file was deleted.

src/main.ts

+16-9
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66

77
import path = require('path');
88
import vscode = require('vscode');
9-
import configuration = require('./features/configuration');
9+
import settingsManager = require('./settings');
1010
import { LanguageClient, LanguageClientOptions, Executable } from 'vscode-languageclient';
1111

1212
import { RequestType, NotificationType, ResponseError } from 'vscode-jsonrpc';
1313
import powerShellMessage = require('./features/ShowOnlineHelp');
1414

1515
export function activate(context: vscode.ExtensionContext): void {
1616

17-
var PowerShellLanguageId = 'PowerShell';
17+
var PowerShellLanguageId = 'powershell';
18+
var settings = settingsManager.load('powershell');
1819

1920
vscode.languages.setLanguageConfiguration(PowerShellLanguageId,
2021
{
@@ -59,10 +60,17 @@ export function activate(context: vscode.ExtensionContext): void {
5960

6061
});
6162

62-
let serverPath = resolveLanguageServerPath();
63+
let args = [];
64+
if (settings.developer.editorServicesWaitForDebugger)
65+
{
66+
args.push('/waitForDebugger');
67+
}
68+
69+
let serverPath = resolveLanguageServerPath(settings);
6370
let serverOptions = {
6471
run: {
65-
command: serverPath,
72+
command: serverPath,
73+
args: args
6674
},
6775
debug: {
6876
command: serverPath,
@@ -99,19 +107,18 @@ export function activate(context: vscode.ExtensionContext): void {
99107
});
100108
}
101109

102-
function resolveLanguageServerPath() : string {
103-
var config = configuration.load('PowerShell');
104-
var editorServicesHostPath = config.editorServicesHostPath;
110+
function resolveLanguageServerPath(settings: settingsManager.ISettings) : string {
111+
var editorServicesHostPath = settings.developer.editorServicesHostPath;
105112

106-
if (config.editorServicesHostPath)
113+
if (editorServicesHostPath)
107114
{
108115
console.log("Found Editor Services path from config: " + editorServicesHostPath);
109116

110117
// Make the path absolute if it's not
111118
editorServicesHostPath =
112119
path.resolve(
113120
__dirname,
114-
config.editorServicesHostPath);
121+
editorServicesHostPath);
115122

116123
console.log(" Resolved path to: " + editorServicesHostPath);
117124
}

src/settings.ts

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*---------------------------------------------------------
2+
* Copyright (C) Microsoft Corporation. All rights reserved.
3+
*--------------------------------------------------------*/
4+
5+
'use strict';
6+
7+
import vscode = require('vscode');
8+
9+
export interface IScriptAnalysisSettings {
10+
enable?: boolean
11+
}
12+
13+
export interface IDeveloperSettings {
14+
editorServicesHostPath?: string;
15+
editorServicesWaitForDebugger?: boolean;
16+
}
17+
18+
export interface ISettings {
19+
scriptAnalysis?: IScriptAnalysisSettings,
20+
developer?: IDeveloperSettings,
21+
}
22+
23+
export function load(myPluginId: string): ISettings {
24+
let configuration = vscode.workspace.getConfiguration(myPluginId);
25+
26+
let defaultScriptAnalysisSettings = {
27+
enable: true
28+
};
29+
30+
let defaultDeveloperSettings = {
31+
editorServicesHostPath: "../bin/Microsoft.PowerShell.EditorServices.Host.exe",
32+
editorServicesWaitForDebugger: false
33+
}
34+
35+
return {
36+
scriptAnalysis: configuration.get<IScriptAnalysisSettings>("scriptAnalysis", defaultScriptAnalysisSettings),
37+
developer: configuration.get<IDeveloperSettings>("developer", defaultDeveloperSettings)
38+
}
39+
}

0 commit comments

Comments
 (0)