@@ -38,25 +38,8 @@ public async Task DiagnosticsRequest_UpdatesUri()
38
38
var document = Workspace . CurrentSolution . GetAdditionalDocument ( _documentId ) . AssumeNotNull ( ) ;
39
39
40
40
var htmlDocumentUri = new Uri ( "file://File.razor.html" , UriKind . Absolute ) ;
41
-
42
- var htmlTextSnapshot = new StringTextSnapshot ( "" ) ;
43
- var htmlTextBuffer = new TestTextBuffer ( htmlTextSnapshot ) ;
44
- var checksum = await document . GetChecksumAsync ( DisposalToken ) ;
45
- var requestInvoker = new TestLSPRequestInvoker ( ( VSInternalMethods . DocumentPullDiagnosticName , null ) ) ;
46
- var lspDocumentManager = new TestDocumentManager ( ) ;
47
- var htmlVirtualDocument = new HtmlVirtualDocumentSnapshot ( htmlDocumentUri , htmlTextBuffer . CurrentSnapshot , hostDocumentSyncVersion : 1 , state : checksum ) ;
48
- var documentSnapshot = new TestLSPDocumentSnapshot ( document . CreateUri ( ) , version : ( int ) ( htmlVirtualDocument . HostDocumentSyncVersion ! . Value + 1 ) , htmlVirtualDocument ) ;
49
- lspDocumentManager . AddDocument ( documentSnapshot . Uri , documentSnapshot ) ;
50
-
51
- var publisher = new TestHtmlDocumentPublisher ( ) ;
52
- var remoteServiceInvoker = new RemoteServiceInvoker ( ) ;
53
- var htmlDocumentSynchronizer = new HtmlDocumentSynchronizer ( remoteServiceInvoker , publisher , LoggerFactory ) ;
54
- var invoker = new HtmlRequestInvoker ( requestInvoker , lspDocumentManager , htmlDocumentSynchronizer , NoOpTelemetryReporter . Instance , LoggerFactory ) ;
55
-
56
- var validated = false ;
57
- requestInvoker . RequestAction = request =>
41
+ var requestValidator = ( object request ) =>
58
42
{
59
- validated = true ;
60
43
var diagnosticParams = Assert . IsType < VSInternalDiagnosticParams > ( request ) ;
61
44
Assert . Equal ( htmlDocumentUri , diagnosticParams . TextDocument ! . DocumentUri . GetRequiredParsedUri ( ) ) ;
62
45
} ;
@@ -66,15 +49,9 @@ public async Task DiagnosticsRequest_UpdatesUri()
66
49
TextDocument = new TextDocumentIdentifier { DocumentUri = document . CreateDocumentUri ( ) }
67
50
} ;
68
51
69
- _ = await invoker . MakeHtmlLspRequestAsync < VSInternalDiagnosticParams , object > (
70
- document ,
71
- VSInternalMethods . DocumentPullDiagnosticName ,
72
- diagnosticRequest ,
73
- DisposalToken ) ;
52
+ await MakeHtmlRequestAsync ( document , htmlDocumentUri , requestValidator , VSInternalMethods . DocumentPullDiagnosticName , diagnosticRequest ) ;
74
53
75
54
Assert . Equal ( document . CreateDocumentUri ( ) , diagnosticRequest . TextDocument ! . DocumentUri ) ;
76
-
77
- Assert . True ( validated ) ;
78
55
}
79
56
80
57
[ Fact ]
@@ -83,11 +60,29 @@ public async Task ITextDocumentParamsRequest_UpdatesUri()
83
60
var document = Workspace . CurrentSolution . GetAdditionalDocument ( _documentId ) . AssumeNotNull ( ) ;
84
61
85
62
var htmlDocumentUri = new Uri ( "file://File.razor.html" , UriKind . Absolute ) ;
63
+ var requestValidator = ( object request ) =>
64
+ {
65
+ var hoverParams = Assert . IsAssignableFrom < ITextDocumentParams > ( request ) ;
66
+ Assert . Equal ( htmlDocumentUri , hoverParams . TextDocument ! . DocumentUri . GetRequiredParsedUri ( ) ) ;
67
+ } ;
68
+
69
+ var hoverRequest = new HoverParams
70
+ {
71
+ TextDocument = new TextDocumentIdentifier { DocumentUri = document . CreateDocumentUri ( ) }
72
+ } ;
73
+
74
+ await MakeHtmlRequestAsync ( document , htmlDocumentUri , requestValidator , Methods . TextDocumentHoverName , hoverRequest ) ;
75
+
76
+ Assert . Equal ( document . CreateDocumentUri ( ) , hoverRequest . TextDocument ! . DocumentUri ) ;
77
+ }
86
78
79
+ private async Task MakeHtmlRequestAsync < TRequest > ( TextDocument document , Uri htmlDocumentUri , Action < object > requestValidator , string method , TRequest request )
80
+ where TRequest : notnull
81
+ {
87
82
var htmlTextSnapshot = new StringTextSnapshot ( "" ) ;
88
83
var htmlTextBuffer = new TestTextBuffer ( htmlTextSnapshot ) ;
89
84
var checksum = await document . GetChecksumAsync ( DisposalToken ) ;
90
- var requestInvoker = new TestLSPRequestInvoker ( ( Methods . TextDocumentHoverName , null ) ) ;
85
+ var requestInvoker = new TestLSPRequestInvoker ( ( method , null ) ) ;
91
86
var lspDocumentManager = new TestDocumentManager ( ) ;
92
87
var htmlVirtualDocument = new HtmlVirtualDocumentSnapshot ( htmlDocumentUri , htmlTextBuffer . CurrentSnapshot , hostDocumentSyncVersion : 1 , state : checksum ) ;
93
88
var documentSnapshot = new TestLSPDocumentSnapshot ( document . CreateUri ( ) , version : ( int ) ( htmlVirtualDocument . HostDocumentSyncVersion ! . Value + 1 ) , htmlVirtualDocument ) ;
@@ -99,26 +94,18 @@ public async Task ITextDocumentParamsRequest_UpdatesUri()
99
94
var invoker = new HtmlRequestInvoker ( requestInvoker , lspDocumentManager , htmlDocumentSynchronizer , NoOpTelemetryReporter . Instance , LoggerFactory ) ;
100
95
101
96
var validated = false ;
102
- requestInvoker . RequestAction = request =>
97
+ requestInvoker . RequestAction = r =>
103
98
{
104
99
validated = true ;
105
- var diagnosticParams = Assert . IsAssignableFrom < ITextDocumentParams > ( request ) ;
106
- Assert . Equal ( htmlDocumentUri , diagnosticParams . TextDocument ! . DocumentUri . GetRequiredParsedUri ( ) ) ;
100
+ requestValidator ( r ) ;
107
101
} ;
108
102
109
- var diagnosticRequest = new HoverParams
110
- {
111
- TextDocument = new TextDocumentIdentifier { DocumentUri = document . CreateDocumentUri ( ) }
112
- } ;
113
-
114
- _ = await invoker . MakeHtmlLspRequestAsync < HoverParams , object > (
103
+ _ = await invoker . MakeHtmlLspRequestAsync < TRequest , object > (
115
104
document ,
116
- Methods . TextDocumentHoverName ,
117
- diagnosticRequest ,
105
+ method ,
106
+ request ,
118
107
DisposalToken ) ;
119
108
120
- Assert . Equal ( document . CreateDocumentUri ( ) , diagnosticRequest . TextDocument ! . DocumentUri ) ;
121
-
122
109
Assert . True ( validated ) ;
123
110
}
124
111
0 commit comments