Skip to content

Commit c71b098

Browse files
Vasily KirichenkoVasily Kirichenko
Vasily Kirichenko
authored and
Vasily Kirichenko
committed
Merge remote-tracking branch 'fsharp/master' into cache-project-response
Conflicts: src/FsAutoComplete.Core/CompilerServiceInterface.fs
2 parents 9e3a886 + 0ba8b77 commit c71b098

File tree

5 files changed

+79
-21
lines changed

5 files changed

+79
-21
lines changed

src/FsAutoComplete.Core/CommandResponse.fs

+8-6
Original file line numberDiff line numberDiff line change
@@ -178,8 +178,9 @@ module CommandResponse =
178178
IsTopLevel: bool
179179
Range: Range.range
180180
BodyRange : Range.range
181+
File : string
181182
}
182-
static member OfDeclarationItem(e:FSharpNavigationDeclarationItem) =
183+
static member OfDeclarationItem(e:FSharpNavigationDeclarationItem, fn) =
183184
let (glyph, glyphChar) = CompletionUtils.getIcon e.Glyph
184185
{
185186
UniqueName = e.UniqueName
@@ -189,6 +190,7 @@ module CommandResponse =
189190
IsTopLevel = e.IsSingleTopLevel
190191
Range = e.Range
191192
BodyRange = e.BodyRange
193+
File = fn
192194
}
193195

194196
type DeclarationResponse = {
@@ -273,11 +275,11 @@ module CommandResponse =
273275
let data = { Line = range.StartLine; Column = range.StartColumn + 1; File = range.FileName }
274276
serialize { Kind = "finddecl"; Data = data }
275277

276-
let declarations (serialize : Serializer) (decls : FSharpNavigationTopLevelDeclaration[]) =
278+
let declarations (serialize : Serializer) (decls : (FSharpNavigationTopLevelDeclaration * string) []) =
277279
let decls' =
278-
decls |> Array.map (fun d ->
279-
{ Declaration = Declaration.OfDeclarationItem d.Declaration;
280-
Nested = d.Nested |> Array.map Declaration.OfDeclarationItem
280+
decls |> Array.map (fun (d, fn) ->
281+
{ Declaration = Declaration.OfDeclarationItem (d.Declaration, fn);
282+
Nested = d.Nested |> Array.map ( fun a -> Declaration.OfDeclarationItem(a,fn))
281283
})
282284
serialize { Kind = "declarations"; Data = decls' }
283285

@@ -298,5 +300,5 @@ module CommandResponse =
298300

299301
let lint (serialize : Serializer) (warnings : LintWarning.Warning list) =
300302
let data = warnings |> List.toArray
301-
303+
302304
serialize { Kind = "lint"; Data = data }

src/FsAutoComplete.Core/Commands.fs

+6
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,15 @@ type Commands (serialize : Serializer) =
9595
| Failure s -> return [Response.error serialize s]
9696
| Success (checkOptions, source) ->
9797
let! decls = checker.GetDeclarations(file, source, checkOptions)
98+
let decls = decls |> Array.map (fun a -> a,file)
9899
return [Response.declarations serialize decls]
99100
}
100101

102+
member __.DeclarationsInProjects () = async {
103+
let! decls = checker.GetDeclarationsInProjects <| state.FileCheckOptions.ToSeq()
104+
return [Response.declarations serialize decls]
105+
}
106+
101107
member __.Helptext sym =
102108
match state.HelpText.TryFind sym with
103109
| None -> [Response.error serialize (sprintf "No help text available for symbol '%s'" sym)]

src/FsAutoComplete.Core/CompilerServiceInterface.fs

+29
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ type FSharpCompilerServiceChecker() =
142142
if s.StartsWith(prefix) then Some (s.Substring(prefix.Length))
143143
else None
144144

145+
let rec allSymbolsInEntities (entities: Collections.Generic.IList<FSharpEntity>) =
146+
[ for e in entities do
147+
yield (e :> FSharpSymbol)
148+
for x in e.MembersFunctionsAndValues do
149+
yield (x :> FSharpSymbol)
150+
for x in e.UnionCases do
151+
yield (x :> FSharpSymbol)
152+
for x in e.FSharpFields do
153+
yield (x :> FSharpSymbol)
154+
yield! allSymbolsInEntities e.NestedEntities ]
155+
145156
member __.GetUsesOfSymbol (options : (SourceFilePath * FSharpProjectOptions) seq, symbol) = async {
146157
let! res =
147158
options
@@ -188,6 +199,24 @@ type FSharpCompilerServiceChecker() =
188199
return parseResult.GetNavigationItems().Declarations
189200
}
190201

202+
member __.GetDeclarationsInProjects (options : seq<string * FSharpProjectOptions>) =
203+
options
204+
|> Seq.distinctBy(fun (_, v) -> v.ProjectFileName)
205+
|> Seq.map (fun (_, opts) -> async {
206+
let! _ = checker.ParseAndCheckProject opts
207+
return!
208+
options
209+
|> Seq.filter (fun (_, projectOpts) -> projectOpts = opts)
210+
|> Seq.map fst
211+
|> Seq.map (fun projectFile -> async {
212+
let! parseRes, _ = checker.GetBackgroundCheckResultsForFileInProject(projectFile, opts)
213+
return (parseRes.GetNavigationItems().Declarations |> Array.map (fun decl -> decl, projectFile))
214+
})
215+
|> Async.Parallel
216+
})
217+
|> Async.Parallel
218+
|> Async.map (Seq.collect (Seq.collect id) >> Seq.toArray)
219+
191220
member __.TryGetProjectOptions (file: SourceFilePath, verbose: bool) : Result<_> =
192221
if not (File.Exists file) then
193222
Failure (sprintf "File '%s' does not exist" file)

src/FsAutoComplete.Suave/FsAutoComplete.Suave.fs

+6
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ let main argv =
8080
return! Response.response HttpCode.HTTP_200 res httpCtx
8181
}
8282
path "/declarations" >=> handler (fun (data : DeclarationsRequest) -> commands.Declarations data.FileName)
83+
path "/declarationsProjects" >=> fun httpCtx ->
84+
async {
85+
let! errors = commands.DeclarationsInProjects ()
86+
let res = errors |> List.toArray |> Json.toJson
87+
return! Response.response HttpCode.HTTP_200 res httpCtx
88+
}
8389
path "/helptext" >=> handler (fun (data : HelptextRequest) -> commands.Helptext data.Symbol |> async.Return)
8490
path "/completion" >=> handler (fun (data : CompletionRequest) -> async {
8591
let file = Path.GetFullPath data.FileName

test/FsAutoComplete.IntegrationTests/Test1Json/output.json

+30-15
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,8 @@
314314
"StartLine": 1,
315315
"EndColumn": 6,
316316
"EndLine": 15
317-
}
317+
},
318+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/Program.fs"
318319
},
319320
"Nested": [
320321
{
@@ -334,7 +335,8 @@
334335
"StartLine": 13,
335336
"EndColumn": 6,
336337
"EndLine": 15
337-
}
338+
},
339+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/Program.fs"
338340
}
339341
]
340342
},
@@ -356,7 +358,8 @@
356358
"StartLine": 1,
357359
"EndColumn": 21,
358360
"EndLine": 2
359-
}
361+
},
362+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/Program.fs"
360363
},
361364
"Nested": [
362365
{
@@ -376,7 +379,8 @@
376379
"StartLine": 2,
377380
"EndColumn": 21,
378381
"EndLine": 2
379-
}
382+
},
383+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/Program.fs"
380384
}
381385
]
382386
}
@@ -403,7 +407,8 @@
403407
"StartLine": 1,
404408
"EndColumn": 6,
405409
"EndLine": 14
406-
}
410+
},
411+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/FileTwo.fs"
407412
},
408413
"Nested": [
409414
{
@@ -423,7 +428,8 @@
423428
"StartLine": 9,
424429
"EndColumn": 20,
425430
"EndLine": 9
426-
}
431+
},
432+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/FileTwo.fs"
427433
},
428434
{
429435
"UniqueName": "FileTwo_1_of_1",
@@ -442,7 +448,8 @@
442448
"StartLine": 7,
443449
"EndColumn": 25,
444450
"EndLine": 7
445-
}
451+
},
452+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/FileTwo.fs"
446453
}
447454
]
448455
},
@@ -464,7 +471,8 @@
464471
"StartLine": 4,
465472
"EndColumn": 8,
466473
"EndLine": 5
467-
}
474+
},
475+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/FileTwo.fs"
468476
},
469477
"Nested": [
470478
{
@@ -484,7 +492,8 @@
484492
"StartLine": 4,
485493
"EndColumn": 8,
486494
"EndLine": 4
487-
}
495+
},
496+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/FileTwo.fs"
488497
},
489498
{
490499
"UniqueName": "Foo_1_of_1",
@@ -503,7 +512,8 @@
503512
"StartLine": 5,
504513
"EndColumn": 8,
505514
"EndLine": 5
506-
}
515+
},
516+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/FileTwo.fs"
507517
}
508518
]
509519
},
@@ -525,7 +535,8 @@
525535
"StartLine": 13,
526536
"EndColumn": 6,
527537
"EndLine": 14
528-
}
538+
},
539+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/FileTwo.fs"
529540
},
530541
"Nested": [
531542
{
@@ -545,7 +556,8 @@
545556
"StartLine": 13,
546557
"EndColumn": 6,
547558
"EndLine": 14
548-
}
559+
},
560+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/FileTwo.fs"
549561
}
550562
]
551563
}
@@ -572,7 +584,8 @@
572584
"StartLine": 1,
573585
"EndColumn": 22,
574586
"EndLine": 4
575-
}
587+
},
588+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/Script.fsx"
576589
},
577590
"Nested": []
578591
},
@@ -594,7 +607,8 @@
594607
"StartLine": 3,
595608
"EndColumn": 22,
596609
"EndLine": 4
597-
}
610+
},
611+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/Script.fsx"
598612
},
599613
"Nested": [
600614
{
@@ -614,7 +628,8 @@
614628
"StartLine": 4,
615629
"EndColumn": 22,
616630
"EndLine": 4
617-
}
631+
},
632+
"File": "<absolute path removed>/FsAutoComplete.IntegrationTests/Test1Json/Script.fsx"
618633
}
619634
]
620635
}

0 commit comments

Comments
 (0)