Skip to content

Commit d4169f1

Browse files
author
Ravi Chande
authored
Merge pull request #2614 from NTaylorMullen/nimullen/updaterazorconfig
Update Razor configurations.
2 parents 2c89f21 + 4df9232 commit d4169f1

File tree

9 files changed

+143
-14
lines changed

9 files changed

+143
-14
lines changed

package.json

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,19 @@
655655
"default": false,
656656
"description": "Specifies whether notifications should be shown if OmniSharp encounters warnings or errors loading a project. Note that these warnings/errors are always emitted to the OmniSharp log"
657657
},
658+
"razor.plugin.path": {
659+
"type": [
660+
"string",
661+
"null"
662+
],
663+
"default": null,
664+
"description": "Overrides the path to the Razor plugin dll."
665+
},
666+
"razor.devmode": {
667+
"type": "boolean",
668+
"default": false,
669+
"description": "Forces the omnisharp-vscode extension to run in a mode that enables local Razor.VSCode deving."
670+
},
658671
"razor.disabled": {
659672
"type": "boolean",
660673
"default": false,
@@ -673,7 +686,7 @@
673686
"default": false,
674687
"description": "Specifies whether to wait for debug attach when launching the language server."
675688
},
676-
"razor.languageServer.trace": {
689+
"razor.trace": {
677690
"type": "string",
678691
"default": "Off",
679692
"enum": [
@@ -682,9 +695,9 @@
682695
"Verbose"
683696
],
684697
"enumDescriptions": [
685-
"Does not log messages from Razor Language Server",
686-
"Logs only some messages from Razor Language Server",
687-
"Logs all messages from Razor Language Server"
698+
"Does not log messages from the Razor extension",
699+
"Logs only some messages from the Razor extension",
700+
"Logs all messages from the Razor extension"
688701
],
689702
"description": "Specifies whether to output all messages [Verbose], some messages [Messages] or not at all [Off]."
690703
}

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import createOptionStream from './observables/CreateOptionStream';
3838
import { CSharpExtensionId } from './constants/CSharpExtensionId';
3939
import { OpenURLObserver } from './observers/OpenURLObserver';
4040
import { activateRazorExtension } from './razor/razor';
41+
import { RazorLoggerObserver } from './observers/RazorLoggerObserver';
4142

4243
export async function activate(context: vscode.ExtensionContext): Promise<CSharpExtensionExports> {
4344

@@ -136,7 +137,12 @@ export async function activate(context: vscode.ExtensionContext): Promise<CSharp
136137
}
137138

138139
if (!optionProvider.GetLatestOptions().razorDisabled) {
139-
await activateRazorExtension(context, extension.extensionPath, eventStream);
140+
const razorObserver = new RazorLoggerObserver(omnisharpChannel);
141+
eventStream.subscribe(razorObserver.post);
142+
143+
if (!optionProvider.GetLatestOptions().razorDevMode) {
144+
await activateRazorExtension(context, extension.extensionPath, eventStream);
145+
}
140146
}
141147

142148
return {
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
import { BaseLoggerObserver } from "./BaseLoggerObserver";
7+
import { RazorPluginPathSpecified, BaseEvent, RazorPluginPathDoesNotExist, RazorDevModeActive } from "../omnisharp/loggingEvents";
8+
9+
export class RazorLoggerObserver extends BaseLoggerObserver {
10+
public post = (event: BaseEvent) => {
11+
switch (event.constructor.name) {
12+
case RazorPluginPathSpecified.name:
13+
this.handleRazorPluginPathSpecifiedMessage(<RazorPluginPathSpecified>event);
14+
break;
15+
case RazorPluginPathDoesNotExist.name:
16+
this.handleRazorPluginPathDoesNotExistMessage(<RazorPluginPathDoesNotExist>event);
17+
break;
18+
case RazorDevModeActive.name:
19+
this.handleRazorDevMode();
20+
break;
21+
}
22+
}
23+
24+
private handleRazorPluginPathSpecifiedMessage(event: RazorPluginPathSpecified) {
25+
this.logger.appendLine('Razor Plugin Path Specified');
26+
this.logger.increaseIndent();
27+
this.logger.appendLine(`Path: ${event.path}`);
28+
this.logger.decreaseIndent();
29+
this.logger.appendLine();
30+
}
31+
32+
private handleRazorPluginPathDoesNotExistMessage(event: RazorPluginPathSpecified) {
33+
this.logger.appendLine(`[error]: Razor plugin path was specified as '${event.path}' but does not exist on disk.`);
34+
}
35+
36+
private handleRazorDevMode() {
37+
this.logger.appendLine('Razor dev mode active. Suppressing built-in OmniSharp Razor support.');
38+
this.logger.appendLine();
39+
}
40+
}

src/omnisharp/extension.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import WorkspaceSymbolProvider from '../features/workspaceSymbolProvider';
2828
import forwardChanges from '../features/changeForwarding';
2929
import registerCommands from '../features/commands';
3030
import { PlatformInformation } from '../platform';
31-
import { ProjectJsonDeprecatedWarning, OmnisharpStart } from './loggingEvents';
31+
import { ProjectJsonDeprecatedWarning, OmnisharpStart, RazorDevModeActive } from './loggingEvents';
3232
import { EventStream } from '../EventStream';
3333
import { NetworkSettingsProvider } from '../NetworkSettings';
3434
import CompositeDisposable from '../CompositeDisposable';
@@ -152,8 +152,14 @@ export async function activate(context: vscode.ExtensionContext, packageJSON: an
152152
});
153153
}));
154154

155-
// read and store last solution or folder path
156-
disposables.add(server.onBeforeServerStart(path => context.workspaceState.update('lastSolutionPathOrFolder', path)));
155+
disposables.add(server.onBeforeServerStart(path => {
156+
if (options.razorDevMode) {
157+
eventStream.post(new RazorDevModeActive());
158+
}
159+
160+
// read and store last solution or folder path
161+
context.workspaceState.update('lastSolutionPathOrFolder', path);
162+
}));
157163

158164
if (options.autoStart) {
159165
server.autoStart(context.workspaceState.get<string>('lastSolutionPathOrFolder'));

src/omnisharp/loggingEvents.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,14 @@ export class OpenURL {
158158
constructor(public url: string) { }
159159
}
160160

161+
export class RazorPluginPathSpecified implements BaseEvent {
162+
constructor(public path: string) {}
163+
}
164+
165+
export class RazorPluginPathDoesNotExist implements BaseEvent {
166+
constructor(public path: string) {}
167+
}
168+
161169
export class DebuggerPrerequisiteFailure extends EventWithMessage { }
162170
export class DebuggerPrerequisiteWarning extends EventWithMessage { }
163171
export class CommandDotNetRestoreProgress extends EventWithMessage { }
@@ -173,6 +181,7 @@ export class DotNetTestRunFailure extends EventWithMessage { }
173181
export class DotNetTestDebugWarning extends EventWithMessage { }
174182
export class DotNetTestDebugStartFailure extends EventWithMessage { }
175183

184+
export class RazorDevModeActive implements BaseEvent { }
176185
export class ProjectModified implements BaseEvent { }
177186
export class ActivationFailure implements BaseEvent { }
178187
export class ShowOmniSharpChannel implements BaseEvent { }

src/omnisharp/options.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ export class Options {
2222
public disableMSBuildDiagnosticWarning: boolean,
2323
public minFindSymbolsFilterLength: number,
2424
public maxFindSymbolsItems: number,
25+
public razorDisabled: boolean,
26+
public razorDevMode: boolean,
27+
public razorPluginPath?: string,
2528
public defaultLaunchSolution?: string,
26-
public monoPath?: string,
27-
public razorDisabled?: boolean) { }
29+
public monoPath?: string) { }
2830

2931

3032
public static Read(vscode: vscode): Options {
@@ -71,6 +73,8 @@ export class Options {
7173
const maxFindSymbolsItems = omnisharpConfig.get<number>('maxFindSymbolsItems', 1000); // The limit is applied only when this setting is set to a number greater than zero
7274

7375
const razorDisabled = !!razorConfig && razorConfig.get<boolean>('disabled', false);
76+
const razorDevMode = !!razorConfig && razorConfig.get<boolean>('devmode', false);
77+
const razorPluginPath = razorConfig ? razorConfig.get<string>('plugin.path', undefined) : undefined;
7478

7579
return new Options(
7680
path,
@@ -88,9 +92,11 @@ export class Options {
8892
disableMSBuildDiagnosticWarning,
8993
minFindSymbolsFilterLength,
9094
maxFindSymbolsItems,
95+
razorDisabled,
96+
razorDevMode,
97+
razorPluginPath,
9198
defaultLaunchSolution,
9299
monoPath,
93-
razorDisabled
94100
);
95101
}
96102

src/omnisharp/server.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import OptionProvider from '../observers/OptionProvider';
3232
import { IMonoResolver } from '../constants/IMonoResolver';
3333
import { removeBOMFromBuffer, removeBOMFromString } from '../utils/removeBOM';
3434

35-
3635
enum ServerState {
3736
Starting,
3837
Started,
@@ -305,9 +304,10 @@ export class OmniSharpServer {
305304
'--loglevel', options.loggingLevel
306305
];
307306

307+
let razorPluginPath: string;
308308
if (!options.razorDisabled) {
309309
// Razor support only exists for certain platforms, so only load the plugin if present
310-
const razorPluginPath = path.join(
310+
razorPluginPath = options.razorPluginPath || path.join(
311311
this.extensionPath,
312312
'.razor',
313313
'OmniSharpPlugin',
@@ -337,6 +337,14 @@ export class OmniSharpServer {
337337
let launchResult = await launchOmniSharp(cwd, args, launchInfo, this.platformInfo, options, this.monoResolver);
338338
this.eventStream.post(new ObservableEvents.OmnisharpLaunch(launchResult.monoVersion, launchResult.monoPath, launchResult.command, launchResult.process.pid));
339339

340+
if (razorPluginPath && options.razorPluginPath) {
341+
if (fs.existsSync(razorPluginPath)) {
342+
this.eventStream.post(new ObservableEvents.RazorPluginPathSpecified(razorPluginPath));
343+
} else {
344+
this.eventStream.post(new ObservableEvents.RazorPluginPathDoesNotExist(razorPluginPath));
345+
}
346+
}
347+
340348
this._serverProcess = launchResult.process;
341349
this._delayTrackers = {};
342350
this._setState(ServerState.Started);

test/unitTests/Fakes/FakeOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
import { Options } from "../../../src/omnisharp/options";
77

88
export function getEmptyOptions(): Options {
9-
return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, 0, 0, "", "");
9+
return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, 0, 0, false, false, undefined, "", "");
1010
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
import { use, should, expect } from 'chai';
6+
import { getNullChannel } from '../testAssets/Fakes';
7+
import { RazorLoggerObserver } from '../../../src/observers/RazorLoggerObserver';
8+
import { RazorPluginPathSpecified, RazorPluginPathDoesNotExist, RazorDevModeActive } from '../../../src/omnisharp/loggingEvents';
9+
10+
use(require("chai-string"));
11+
12+
suite("RazorLoggerObserver", () => {
13+
suiteSetup(() => should());
14+
let logOutput = "";
15+
let observer = new RazorLoggerObserver({
16+
...getNullChannel(),
17+
append: (text: string) => { logOutput += text; },
18+
});
19+
20+
setup(() => {
21+
logOutput = "";
22+
});
23+
24+
test(`RazorPluginPathSpecified: Path is logged`, () => {
25+
let event = new RazorPluginPathSpecified("somePath");
26+
observer.post(event);
27+
expect(logOutput).to.contain(event.path);
28+
});
29+
30+
test(`RazorPluginPathDoesNotExist: Path is logged`, () => {
31+
let event = new RazorPluginPathDoesNotExist("somePath");
32+
observer.post(event);
33+
expect(logOutput).to.contain(event.path);
34+
});
35+
36+
test(`RazorDevModeActive: Logs dev mode active`, () => {
37+
let event = new RazorDevModeActive();
38+
observer.post(event);
39+
expect(logOutput).to.contain('Razor dev mode active');
40+
});
41+
});

0 commit comments

Comments
 (0)