Skip to content

Commit

Permalink
improve reference count codelens
Browse files Browse the repository at this point in the history
  • Loading branch information
yatli committed Jun 17, 2019
1 parent ef4e21a commit 5e85d78
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"author": "Yatao Li",
"license": "MIT",
"icon": "Icon512.png",
"version": "0.1.47",
"version": "0.1.48",
"publisher": "yatli",
"repository": {
"type": "git",
Expand Down
17 changes: 14 additions & 3 deletions src/FSharpLanguageServer/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,10 @@ type Server(client: ILanguageClient) =
/// Send diagnostics to the client
let publishErrors(file: FileInfo, errors: Diagnostic list) =
client.PublishDiagnostics({uri=Uri("file://" + file.FullName); diagnostics=errors})

/// Maps the file paths to the hash code of used symbols
let fileSymbolUses = System.Collections.Generic.Dictionary<string, string[]>()

/// Check a file
let getErrors(file: FileInfo, check: Result<FSharpParseFileResults * FSharpCheckFileResults, Diagnostic list>): Async<Diagnostic list> =
async {
Expand All @@ -330,6 +334,8 @@ type Server(client: ILanguageClient) =
let unusedDeclarationRanges = UnusedDeclarations.getUnusedDeclarationRanges(uses, file.Name.EndsWith(".fsx"))
let unusedDeclarationErrors = [for r in unusedDeclarationRanges do yield diagnostic("Unused declaration", r, DiagnosticSeverity.Hint)]
dprintfn "Found %d unused declarations in %dms" unusedDeclarationErrors.Length timeUnusedDeclarations.ElapsedMilliseconds

fileSymbolUses.[file.FullName] <- Array.map (fun (x: FSharpSymbolUse) -> x.Symbol.FullName) uses
// Combine
// return parseErrors@typeErrors@unusedOpenErrors@unusedDeclarationErrors
return parseErrors@typeErrors@unusedDeclarationErrors
Expand Down Expand Up @@ -511,16 +517,21 @@ type Server(client: ILanguageClient) =
async {
let range = node.Range
let! sym = symbolAt({uri = Uri(range.FileName)}, {line = range.StartLine - 1; character = range.StartColumn})
let cnt = ref 0
match sym with
| Some sym -> do! findReferenceK(sym.Symbol, fun _ -> cnt := !cnt + 1)
| Some sym ->
let sym = sym.Symbol.FullName
let mutable cnt = 0
for KeyValue(_, v) in fileSymbolUses do
for v in v do
if v = sym then cnt <- cnt + 1
return cnt
| _ ->
dprintfn "findReferenceCount: symbol resolve fails. node = %A"
(node.Range.FileName, node.Range.StartLine, node.Range.StartColumn,
node.bodyRange.StartLine, node.bodyRange.StartColumn,
node.Glyph, node.Name, node.Kind, node.Access, node.FSharpEnclosingEntityKind
)
return !cnt
return 0
}

/// Find all uses of a symbol, across all open projects
Expand Down

0 comments on commit 5e85d78

Please sign in to comment.