@@ -515,6 +515,10 @@ namespace ts.projectSystem {
515
515
return session . executeCommand ( makeSessionRequest ( command , args ) ) . response as TResponse [ "body" ] ;
516
516
}
517
517
518
+ export function executeSessionRequestNoResponse < TRequest extends protocol . Request > ( session : server . Session , command : TRequest [ "command" ] , args : TRequest [ "arguments" ] ) : void {
519
+ session . executeCommand ( makeSessionRequest ( command , args ) ) ;
520
+ }
521
+
518
522
export function openFilesForSession ( files : ReadonlyArray < File | { readonly file : File | string , readonly projectRootPath : string } > , session : server . Session ) : void {
519
523
for ( const file of files ) {
520
524
session . executeCommand ( makeSessionRequest < protocol . OpenRequestArgs > ( CommandNames . Open ,
@@ -9256,6 +9260,50 @@ export function Test2() {
9256
9260
} ) ;
9257
9261
} ) ;
9258
9262
9263
+ describe ( "Untitled files" , ( ) => {
9264
+ it ( "Can convert positions to locations" , ( ) => {
9265
+ const aTs : File = { path : "/proj/a.ts" , content : "" } ;
9266
+ const tsconfig : File = { path : "/proj/tsconfig.json" , content : "{}" } ;
9267
+ const session = createSession ( createServerHost ( [ aTs , tsconfig ] ) ) ;
9268
+
9269
+ openFilesForSession ( [ aTs ] , session ) ;
9270
+
9271
+ const untitledFile = "untitled:^Untitled-1" ;
9272
+ executeSessionRequestNoResponse < protocol . OpenRequest > ( session , protocol . CommandTypes . Open , {
9273
+ file : untitledFile ,
9274
+ fileContent : "let foo = 1;\nfooo/**/" ,
9275
+ scriptKindName : "TS" ,
9276
+ projectRootPath : "/proj" ,
9277
+ } ) ;
9278
+
9279
+ const response = executeSessionRequest < protocol . CodeFixRequest , protocol . CodeFixResponse > ( session , protocol . CommandTypes . GetCodeFixes , {
9280
+ file : untitledFile ,
9281
+ startLine : 2 ,
9282
+ startOffset : 1 ,
9283
+ endLine : 2 ,
9284
+ endOffset : 5 ,
9285
+ errorCodes : [ Diagnostics . Cannot_find_name_0_Did_you_mean_1 . code ] ,
9286
+ } ) ;
9287
+ assert . deepEqual < ReadonlyArray < protocol . CodeFixAction > | undefined > ( response , [
9288
+ {
9289
+ description : "Change spelling to 'foo'" ,
9290
+ fixAllDescription : "Fix all detected spelling errors" ,
9291
+ fixId : "fixSpelling" ,
9292
+ fixName : "spelling" ,
9293
+ changes : [ {
9294
+ fileName : untitledFile ,
9295
+ textChanges : [ {
9296
+ start : { line : 2 , offset : 1 } ,
9297
+ end : { line : 2 , offset : 5 } ,
9298
+ newText : "foo" ,
9299
+ } ] ,
9300
+ } ] ,
9301
+ commands : undefined ,
9302
+ } ,
9303
+ ] ) ;
9304
+ } ) ;
9305
+ } ) ;
9306
+
9259
9307
function makeReferenceItem ( file : File , isDefinition : boolean , text : string , lineText : string , options ?: SpanFromSubstringOptions ) : protocol . ReferencesResponseItem {
9260
9308
return {
9261
9309
...protocolFileSpanFromSubstring ( file , text , options ) ,
0 commit comments