Skip to content

Commit

Permalink
suggest: symToSuggest limit data per IdeCmd (#908)
Browse files Browse the repository at this point in the history
## Summary

`suggest.symToSuggest` now restrict data fetched based on the `IdeCmd`
given. Meaning some `Suggest` fields are only filled in/used given
specific `IdeCmd`(s), avoiding unnecessary processing.

## Details

* Fill `contextFits`,`globalUsages`,`localUsages` fields when `IdeCmd`
in
`{ideSug, ideCon}`. they're used in `cmpSuggestions` -> `produceOutput`.
* Fill `doc` field when `IdeCmd` is not `ideHighlight`. `ideHighlight`
  results don't render the documentation comment, see `$(Suggest)`

---------

Co-authored-by: zerbina <100542850+zerbina@users.noreply.github.com>
  • Loading branch information
bung87 and zerbina authored Sep 21, 2023
1 parent 24f4e69 commit 8beb528
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions compiler/tools/suggest.nim
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,17 @@ proc symToSuggest(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info:
result.quality = quality
result.isGlobal = sfGlobal in s.flags
result.prefix = prefix
result.contextFits = inTypeContext == (s.kind in {skType, skGenericParam})
if section in {ideSug, ideCon}:
result.contextFits = inTypeContext == (s.kind in {skType, skGenericParam})
result.scope = scope
result.name = addr s.name.s
when defined(nimsuggest):
result.globalUsages = s.allUsages.len
var c = 0
for u in s.allUsages:
if u.fileIndex == info.fileIndex: inc c
result.localUsages = c
if section in {ideSug, ideCon}:
result.globalUsages = s.allUsages.len
var c = 0
for u in s.allUsages:
if u.fileIndex == info.fileIndex: inc c
result.localUsages = c
result.symkind = byte s.kind
result.qualifiedPath = @[]
if not isLocal and s.kind != skModule:
Expand All @@ -191,7 +193,8 @@ proc symToSuggest(g: ModuleGraph; s: PSym, isLocal: bool, section: IdeCmd, info:
else:
result.forth = ""
when defined(nimsuggest) and not defined(noDocgen) and not defined(leanCompiler):
result.doc = extractDocComment(g, s)
if section != ideHighlight:
result.doc = extractDocComment(g, s)
let infox =
if useSuppliedInfo or section in {ideUse, ideHighlight, ideOutline}:
info
Expand Down

0 comments on commit 8beb528

Please sign in to comment.