Skip to content

Commit 6b0da5b

Browse files
authored
Fix custom Razor commands for cohosting (#8251)
2 parents d8c8cd0 + f78f7ee commit 6b0da5b

File tree

7 files changed

+35
-63
lines changed

7 files changed

+35
-63
lines changed

l10n/bundle.l10n.json

+1
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@
103103
"Non Razor file as active document": "Non Razor file as active document",
104104
"Could not determine CSharp content": "Could not determine CSharp content",
105105
"Could not determine Html content": "Could not determine Html content",
106+
"Cohosting is on, client has no access to CSharp content": "Cohosting is on, client has no access to CSharp content",
106107
"A valid dotnet installation could not be found: {0}": "A valid dotnet installation could not be found: {0}",
107108
"Is this a Bug or Feature request?": "Is this a Bug or Feature request?",
108109
"Bug": "Bug",

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -1881,12 +1881,14 @@
18811881
{
18821882
"command": "extension.showRazorCSharpWindow",
18831883
"title": "%command.extension.showRazorCSharpWindow%",
1884-
"category": "Razor"
1884+
"category": "Razor",
1885+
"enablement": "razor.mode == 'lsp'"
18851886
},
18861887
{
18871888
"command": "extension.showRazorHtmlWindow",
18881889
"title": "%command.extension.showRazorHtmlWindow%",
1889-
"category": "Razor"
1890+
"category": "Razor",
1891+
"enablement": "razor.mode == 'lsp'"
18901892
},
18911893
{
18921894
"command": "razor.reportIssue",

src/lsptoolshost/razor/razorEndpoints.ts

+5
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import { MappingHandler } from '../../razor/src/mapping/mappingHandler';
4949
import { RazorMapTextChangesParams } from '../../razor/src/mapping/razorMapTextChangesParams';
5050
import { RazorMapTextChangesResponse } from '../../razor/src/mapping/razorMapTextChangesResponse';
5151
import { FormattingHandler } from '../../razor/src/formatting/formattingHandler';
52+
import { ReportIssueCommand } from '../../razor/src/diagnostics/reportIssueCommand';
5253

5354
export function registerRazorEndpoints(
5455
context: vscode.ExtensionContext,
@@ -62,8 +63,10 @@ export function registerRazorEndpoints(
6263
);
6364

6465
if (razorOptions.cohostingEnabled) {
66+
vscode.commands.executeCommand('setContext', 'razor.mode', 'cohosting');
6567
registerCohostingEndpoints();
6668
} else {
69+
vscode.commands.executeCommand('setContext', 'razor.mode', 'lsp');
6770
registerNonCohostingEndpoints();
6871
}
6972

@@ -74,7 +77,9 @@ export function registerRazorEndpoints(
7477
//
7578
function registerCohostingEndpoints() {
7679
const documentManager = new HtmlDocumentManager(platformInfo, razorLogger);
80+
const reportIssueCommand = new ReportIssueCommand(vscode, undefined, documentManager, razorLogger);
7781
context.subscriptions.push(documentManager.register());
82+
context.subscriptions.push(reportIssueCommand.register());
7883

7984
registerMethodHandler<HtmlUpdateParameters, void>('razor/updateHtml', async (params) => {
8085
const uri = UriConverter.deserialize(params.textDocument.uri);

src/razor/src/diagnostics/razorIssueDataCollector.ts

-50
This file was deleted.

src/razor/src/diagnostics/reportIssueCommand.ts

+8-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { HtmlDocumentManager } from '../../../lsptoolshost/razor/htmlDocumentManager';
67
import { RazorDocumentManager } from '../document/razorDocumentManager';
78
import { RazorLogger } from '../razorLogger';
89
import { api } from '../vscodeAdapter';
@@ -16,9 +17,14 @@ export class ReportIssueCommand {
1617
private readonly issueCreator: ReportIssueCreator;
1718
private readonly dataCollectorFactory: ReportIssueDataCollectorFactory;
1819

19-
constructor(private readonly vscodeApi: api, documentManager: RazorDocumentManager, logger: RazorLogger) {
20+
constructor(
21+
private readonly vscodeApi: api,
22+
documentManager: RazorDocumentManager | undefined,
23+
cohostingDocumentManager: HtmlDocumentManager | undefined,
24+
logger: RazorLogger
25+
) {
2026
this.dataCollectorFactory = new ReportIssueDataCollectorFactory(logger);
21-
this.issueCreator = new ReportIssueCreator(this.vscodeApi, documentManager);
27+
this.issueCreator = new ReportIssueCreator(this.vscodeApi, documentManager, cohostingDocumentManager);
2228
this.issuePanel = new ReportIssuePanel(this.dataCollectorFactory, this.issueCreator, logger);
2329
}
2430

src/razor/src/diagnostics/reportIssueCreator.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,36 @@ import { IRazorDocument } from '../document/IRazorDocument';
1111
import { IRazorDocumentManager } from '../document/IRazorDocumentManager';
1212
import { razorExtensionId } from '../razorExtensionId';
1313
import { IReportIssueDataCollectionResult } from './IReportIssueDataCollectionResult';
14+
import { HtmlDocumentManager } from '../../../lsptoolshost/razor/htmlDocumentManager';
1415

1516
export class ReportIssueCreator {
1617
constructor(
1718
private readonly vscodeApi: vscodeAdapter.api,
18-
private readonly documentManager: IRazorDocumentManager
19+
private readonly documentManager?: IRazorDocumentManager,
20+
private readonly cohostingDocumentManager?: HtmlDocumentManager
1921
) {}
2022

2123
public async create(collectionResult: IReportIssueDataCollectionResult) {
2224
let razorContent: string;
2325
let csharpContent: string;
2426
let htmlContent: string;
2527

28+
razorContent = vscode.l10n.t('Non Razor file as active document');
29+
csharpContent = vscode.l10n.t('Could not determine CSharp content');
30+
htmlContent = vscode.l10n.t('Could not determine Html content');
31+
2632
if (collectionResult.document) {
2733
razorContent = await this.getRazor(collectionResult.document);
2834

29-
const razorDocument = await this.documentManager.getDocument(collectionResult.document.uri);
30-
csharpContent = await this.getProjectedCSharp(razorDocument);
31-
htmlContent = await this.getProjectedHtml(razorDocument);
32-
} else {
33-
razorContent = vscode.l10n.t('Non Razor file as active document');
34-
csharpContent = vscode.l10n.t('Could not determine CSharp content');
35-
htmlContent = vscode.l10n.t('Could not determine Html content');
35+
if (this.documentManager) {
36+
const razorDocument = await this.documentManager.getDocument(collectionResult.document.uri);
37+
csharpContent = await this.getProjectedCSharp(razorDocument);
38+
htmlContent = await this.getProjectedHtml(razorDocument);
39+
} else if (this.cohostingDocumentManager) {
40+
const htmlDocument = await this.cohostingDocumentManager.getDocument(collectionResult.document.uri);
41+
csharpContent = vscode.l10n.t('Cohosting is on, client has no access to CSharp content');
42+
htmlContent = htmlDocument.getContent();
43+
}
3644
}
3745

3846
const razorExtensionVersion = this.getExtensionVersion();

src/razor/src/extension.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ export async function activate(
139139
const csharpFeature = new RazorCSharpFeature(documentManager, eventEmitterFactory, logger);
140140
const htmlFeature = new RazorHtmlFeature(documentManager, languageServiceClient, eventEmitterFactory, logger);
141141
const localRegistrations: vscode.Disposable[] = [];
142-
const reportIssueCommand = new ReportIssueCommand(vscodeType, documentManager, logger);
142+
const reportIssueCommand = new ReportIssueCommand(vscodeType, documentManager, undefined, logger);
143143
const razorCodeActionRunner = new RazorCodeActionRunner(languageServerClient, logger);
144144
const codeActionsHandler = new CodeActionsHandler(
145145
documentManager,

0 commit comments

Comments
 (0)