Skip to content

Commit 6449bdc

Browse files
authored
implement vscode side of fsautocomplete#817 (#1680)
1 parent 66e4a6a commit 6449bdc

File tree

2 files changed

+11
-46
lines changed

2 files changed

+11
-46
lines changed

src/Components/SignatureData.fs

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -17,48 +17,8 @@ module SignatureData =
1717
let line = editor.selection.active.line
1818
let col = editor.selection.active.character
1919

20-
LanguageService.generateDocumentation document.fileName (int line) (int col)
21-
|> Promise.bind (fun (p: SignatureDataResult) ->
22-
promise {
23-
let pms =
24-
p.Data.Parameters
25-
|> Seq.concat
26-
|> Seq.where (fun prm -> String.IsNullOrWhiteSpace prm.Name |> not)
27-
|> Seq.map (fun prm -> sprintf """/// <param name="%s"></param>""" prm.Name)
28-
|> String.concat "\n"
29-
30-
let generics =
31-
p.Data.Generics
32-
|> Seq.map (fun generic -> sprintf """/// <typeparam name="'%s"></typeparam>""" generic)
33-
|> String.concat "\n"
34-
35-
let comment =
36-
[ yield "/// <summary>"
37-
yield "/// "
38-
yield "/// </summary>"
39-
if pms <> "" then yield pms
40-
if generics <> "" then yield generics
41-
yield "/// <returns></returns>" ]
42-
|> String.concat "\n"
43-
44-
let x = editor.selection.active.line
45-
let t = document.getText (vscode.Range.Create(x, 0., x, 1000.))
46-
let t' = t.TrimStart(' ')
47-
let spsC = t.Length - t'.Length
48-
let sps = String.replicate spsC " "
49-
50-
let cmnt =
51-
comment
52-
|> String.split [| '\n' |]
53-
|> Seq.map (fun n -> sprintf "%s%s" sps n)
54-
|> String.concat "\n"
55-
56-
let edit = vscode.WorkspaceEdit.Create()
57-
edit.insert (document.uri, vscode.Position.Create(x, 0.), cmnt + "\n")
58-
return! workspace.applyEdit edit
59-
})
60-
|> ignore
61-
| _ -> ()
20+
LanguageService.generateDocumentation (document.uri, document.version) (int line, int col)
21+
| _ -> Promise.lift ()
6222

6323

6424
let activate (context: ExtensionContext) =

src/Core/LanguageService.fs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,16 @@ module LanguageService =
5252
type DocumentUri = string
5353

5454
type TextDocumentIdentifier = { Uri: DocumentUri }
55+
type VersionedTextDocumentIdentifier = { Uri: DocumentUri; Version: float }
5556

5657
type TextDocumentPositionParams =
5758
{ TextDocument: TextDocumentIdentifier
5859
Position: Position }
5960

61+
type VersionedTextDocumentPositionParams =
62+
{ TextDocument: VersionedTextDocumentIdentifier
63+
Position: Position }
64+
6065
type FileParams = { Project: TextDocumentIdentifier }
6166

6267
type WorkspaceLoadParms =
@@ -184,16 +189,16 @@ module LanguageService =
184189
cl.sendRequest ("fsharp/signatureData", req)
185190
|> Promise.map (fun (res: Types.PlainNotification) -> res.content |> ofJson<SignatureDataResult>)
186191

187-
let generateDocumentation fn line col =
192+
let generateDocumentation (fileUri: Uri, version) (line, col) =
188193
match client with
189194
| None -> Promise.empty
190195
| Some cl ->
191-
let req: Types.TextDocumentPositionParams =
192-
{ TextDocument = { Uri = handleUntitled fn }
196+
let req: Types.VersionedTextDocumentPositionParams =
197+
{ TextDocument = { Uri = fileUri.toString(); Version = version }
193198
Position = { Line = line; Character = col } }
194199

195200
cl.sendRequest ("fsharp/documentationGenerator", req)
196-
|> Promise.map (fun (res: Types.PlainNotification) -> res.content |> ofJson<SignatureDataResult>)
201+
|> Promise.map (fun _ -> ())
197202

198203
let lineLenses fn =
199204
match client with

0 commit comments

Comments
 (0)