@@ -32,6 +32,7 @@ import {
3232} from 'vscode-languageclient/node' ;
3333import { PlatformInformation } from '../../shared/platform' ;
3434import { readConfigurations } from '../options/configurationMiddleware' ;
35+ import { DynamicFileInfoHandler } from '../../razor/src/dynamicFile/dynamicFileInfoHandler' ;
3536import * as RoslynProtocol from './roslynProtocol' ;
3637import { CSharpDevKitExports } from '../../csharpDevKitExports' ;
3738import { SolutionSnapshotId } from '../solutionSnapshot/ISolutionSnapshotProvider' ;
@@ -59,13 +60,16 @@ import { BuildDiagnosticsService } from '../diagnostics/buildDiagnosticsService'
5960import { getComponentPaths } from '../extensions/builtInComponents' ;
6061import { OnAutoInsertFeature } from '../autoInsert/onAutoInsertFeature' ;
6162import { ProjectContextService } from '../projectContext/projectContextService' ;
63+ import { ProvideDynamicFileResponse } from '../../razor/src/dynamicFile/provideDynamicFileResponse' ;
64+ import { ProvideDynamicFileParams } from '../../razor/src/dynamicFile/provideDynamicFileParams' ;
6265import {
6366 ActionOption ,
6467 CommandOption ,
6568 showErrorMessage ,
6669 showInformationMessage ,
6770} from '../../shared/observers/utils/showMessage' ;
6871import { TelemetryEventNames } from '../../shared/telemetryEventNames' ;
72+ import { RazorDynamicFileChangedParams } from '../../razor/src/dynamicFile/dynamicFileUpdatedParams' ;
6973import { getProfilingEnvVars } from '../profiling/profiling' ;
7074import { isString } from '../utils/isString' ;
7175import { getServerPath } from '../activate' ;
@@ -80,6 +84,10 @@ import {
8084let _wasActivatedWithCSharpDevkit : boolean | undefined ;
8185
8286export class RoslynLanguageServer {
87+ // These are notifications we will get from the LSP server and will forward to the Razor extension.
88+ private static readonly provideRazorDynamicFileInfoMethodName : string = 'razor/provideDynamicFileInfo' ;
89+ private static readonly removeRazorDynamicFileInfoMethodName : string = 'razor/removeDynamicFileInfo' ;
90+
8391 /**
8492 * The encoding to use when writing to and from the stream.
8593 */
@@ -134,6 +142,10 @@ export class RoslynLanguageServer {
134142 this . registerDocumentOpenForDiagnostics ( ) ;
135143
136144 this . _projectContextService = new ProjectContextService ( this , this . _languageServerEvents ) ;
145+
146+ // Register Razor dynamic file info handling
147+ this . registerDynamicFileInfo ( ) ;
148+
137149 this . registerDebuggerAttach ( ) ;
138150
139151 registerShowToastNotification ( this . _languageClient ) ;
@@ -803,6 +815,37 @@ export class RoslynLanguageServer {
803815 } ;
804816 }
805817
818+ private ProvideDyanmicFileInfoType : RequestType < ProvideDynamicFileParams , ProvideDynamicFileResponse , any > =
819+ new RequestType ( RoslynLanguageServer . provideRazorDynamicFileInfoMethodName ) ;
820+
821+ private registerDynamicFileInfo ( ) {
822+ // When the Roslyn language server sends a request for Razor dynamic file info, we forward that request along to Razor via
823+ // a command.
824+ this . _languageClient . onRequest < ProvideDynamicFileParams , ProvideDynamicFileResponse , any > (
825+ this . ProvideDyanmicFileInfoType ,
826+ async ( request ) =>
827+ vscode . commands . executeCommand ( DynamicFileInfoHandler . provideDynamicFileInfoCommand , request )
828+ ) ;
829+ this . _languageClient . onNotification (
830+ RoslynLanguageServer . removeRazorDynamicFileInfoMethodName ,
831+ async ( notification ) =>
832+ vscode . commands . executeCommand ( DynamicFileInfoHandler . removeDynamicFileInfoCommand , notification )
833+ ) ;
834+ vscode . commands . registerCommand (
835+ DynamicFileInfoHandler . dynamicFileUpdatedCommand ,
836+ async ( notification : RazorDynamicFileChangedParams ) => {
837+ if ( this . isRunning ( ) ) {
838+ await this . sendNotification < RazorDynamicFileChangedParams > (
839+ 'razor/dynamicFileInfoChanged' ,
840+ notification
841+ ) ;
842+ } else {
843+ this . _channel . warn ( 'Tried to send razor/dynamicFileInfoChanged while server is not running' ) ;
844+ }
845+ }
846+ ) ;
847+ }
848+
806849 // eslint-disable-next-line @typescript-eslint/promise-function-async
807850 private WaitForAttachCompleteAsync ( attachRequestId : string ) : Promise < boolean > {
808851 return new Promise < boolean > ( ( resolve ) => {
0 commit comments