summary refs log tree commit diff stats
path: root/compiler/suggest.nim
Commit message (Collapse)AuthorAgeFilesLines
* fixes #22409; don't check style for enumFieldSymChoice in the function (#23580)ringabout2024-05-081-2/+3
| | | fixes #22409
* + added nimsuggest support for exception inlay hints (#23202)Nikolay Nikolov2024-03-151-3/+41
| | | | | | | | | | | | | | | | | This adds nimsuggest support for displaying inlay hints for exceptions. An inlay hint is displayed around function calls, that can raise an exception, which isn't handled in the current subroutine (in other words, exceptions that can propagate back to the caller). On mouse hover on top of the hint, a list of exceptions that could propagate is shown. The changes, required to support this are already commited to nimlangserver and the VS code extension. The extension and the server allow configuration for whether these new exception hints are enabled (they can be enabled or disabled independently from the type hints), as well as the inlay strings that are inserted before and after the name of the function, around the function call. Potentially, one of these strings can be empty, for example, the user can choose to add an inlay hint only before the name of the function, or only after the name of the function.
* refactoring: no inheritance for PType/PSym (#23403)Andreas Rumpf2024-03-141-1/+1
|
* + show the inferred exception list (as part of the type) for functions that ↵Nikolay Nikolov2024-01-151-1/+1
| | | | don't have an explicit `.raises` pragma (#23193)
* types refactoring; WIP (#23086)Andreas Rumpf2023-12-171-2/+2
|
* Skip trailing asterisk when placing inlay type hints. Fixes #23067 (#23068)Nikolay Nikolov2023-12-131-2/+13
|
* type refactoring: part 2 (#23059)Andreas Rumpf2023-12-131-12/+12
|
* Only suggest symbols that could be pragmas when typing a pragma (#23040)Jake Leahy2023-12-071-2/+35
| | | | | | Currently pragmas just fall through to `suggestSentinel` and show everything which isn't very useful. Now it filters for symbols that could be pragmas (templates with `{.pragma.}`, macros, user pragmas) and only shows them
* Don't provide suggestions for enum fields (#22959)Jake Leahy2023-11-201-0/+3
| | | | | | | | | Currently the suggestions create a lot of noise when creating enum fields. I don't see any way of a macro creating fields (when called inside an enum) so it should be safe to not show suggestions --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* nimsuggest: Instead of checking for protocol version 3 exactly, check for ↵Nikolay Nikolov2023-11-151-2/+2
| | | | | | | | | version 3 or later. (#22945) Refactored the way nimsuggest checks for protocol version 3. Instead of checking for version 3 exactly, it now checks for version 3 or later. This way, once a version 4 is introduced, it will use version 3 as a base line, and then extra changes to the protocol can be added on top. No functional changes are introduced in this commit.
* Inlay hints for types of consts (#22916)Nikolay Nikolov2023-11-071-1/+4
| | | This adds inlay hint support for the types of consts.
* Inlay hints support (#22896)Nikolay Nikolov2023-11-041-41/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | This adds inlay hints support to nimsuggest. It adds a new command to nimsuggest, called 'inlayHints'. Currently, it provides type information to 'var' and 'let' variables. In the future, inlay hints can also be added for 'const' and for function parameters. The protocol also reserves space for a tooltip field, which is not used, yet, but support for it can be added in the future, without further changing the protocol. The change includes refactoring to allow the 'inlayHints' command to return a completely different structure, compared to the other nimsuggest commands. This will allow other future commands to have custom return types as well. All the previous commands return the same structure as before, so perfect backwards compatibility is maintained. To use this feature, an update to the nim language server, as well as the VS code extension is needed. Related PRs: nimlangserver: https://github.com/nim-lang/langserver/pull/53 VS code extension: https://github.com/saem/vscode-nim/pull/134 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* prepare for the enforcement of `std` prefix (#22873)ringabout2023-10-291-2/+4
| | | follow up https://github.com/nim-lang/Nim/pull/22851
* fix sym of created generic instantiation type (#22642)metagn2023-09-051-4/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #22639 A `tyGenericInst` has its last son as the instantiated body of the original generic type. However this type keeps its original `sym` field from the original generic types, which means the sym's type is uninstantiated. This causes problems in the implementation of `getType`, where it uses the `sym` fields of types to represent them in AST, the relevant example for the issue being [here](https://github.com/nim-lang/Nim/blob/d13aab50cf465a7f2edf9c37a4fa30e128892e72/compiler/vmdeps.nim#L191) called from [here](https://github.com/nim-lang/Nim/blob/d13aab50cf465a7f2edf9c37a4fa30e128892e72/compiler/vmdeps.nim#L143). To fix this, create a new symbol from the original symbol for the instantiated body during the creation of `tyGenericInst`s with the appropriate type. Normally `replaceTypeVarsS` would be used for this, but here it seems to cause some recursion issue (immediately gives an error like "cannot instantiate HSlice[T, U]"), so we directly set the symbol's type to the instantiated type. Avoiding recursion means we also cannot use `replaceTypeVarsN` for the symbol AST, and the symbol not having any AST crashes the implementation of `getType` again [here](https://github.com/nim-lang/Nim/blob/d13aab50cf465a7f2edf9c37a4fa30e128892e72/compiler/vmdeps.nim#L167), so the symbol AST is set to the original generic type AST for now which is what it was before anyway. Not sure about this because not sure why the recursion issue is happening, putting it at the end of the proc doesn't help either. Also not sure if the `cl.owner != nil and s.owner != cl.owner` condition from `replaceTypeVarsS` is relevant here. This might also break some code if it depended on the original generic type symbol being given.
* use strictdefs for compiler (#22365)ringabout2023-08-061-9/+24
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* Fix nimsuggest not showing suggestions for imported tuples (#22241)Jake Leahy2023-07-101-1/+9
| | | | | | | | | | | * Add tests Also test if exported all tuple fields works. This seems like a hacky solution so will try and dive further to find a better solution * Always suggest tuple fields if it passes the filter If the tuple we are accessing is in scope then all the fields will also be in scope * Update tests so line numbers are correct
* privateAccess ignores non-objects (#21973)metagn2023-06-011-0/+1
| | | closes #21969
* warn on set types bigger than max size, default to 0..255 for int literals ↵metagn2023-04-171-1/+1
| | | | | | | | | | | | | | | | | | | (#21659) * test implicitly huge set types refs https://github.com/nim-lang/RFCs/issues/298 * oh my god * boot at least * don't error, fix remaining issues, no 2 len arrays * fix runnable example * test assuming 0..255 for int literal * test refactor, add changelog, test
* replaces implicit passes array registed at runtime with explicit function ↵ringabout2023-03-031-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | calls; simplify compilation pipeline (#21444) * abolish using passes in the compiler; simplify compilation pipeline * duplicate code * Really cool to have the same signature... * haul * unify other backends * refactor process * introduce PipelinePhase * refactor compiler * fixes passes * fixes nimsuggest * add a sentinel * enable docs checkj * activate doc testing * clean up * complete cleanups
* Implemented basic macro expand functionality (#20579)Ivan Yonchovski2023-01-271-1/+11
| | | | | | | | | | | | | | | | | | * Implemented level based macro expand functionality - it can handle single macro call or expand whole function/proc/etc and it - In addition, I have altered the parser to provide the endInfo for the node. The usefulness of the `endInfo` is not limited to the `expandMacro` functionality but also it is useful for `ideOutline` functionality and I have altered the ideOutline functionality to use `endInfo`. Note `endInfo` most of the time is lost during the AST transformation thus in `nimsuggest.nim` I am using freshly parsed tree to get the location information. * Make sure we stop expanding correctly * Test CI * Fix tv3_outline.nim
* Don't repeat suggestions for same symbol (#21140)Jake Leahy2022-12-221-3/+3
| | | | | | | | | | * Track seen module graphs so symbols from the same module aren't repeated Add test case * Track symbols instead of modules * Don't show duplicate symbols in spell checker Removes the declared location from the message. Since we don't show duplicates anymore it would be a bit misleading if we only show the location for the first declaration of the symbol
* fixes #19278; make `privateAccess` work with generic ref object (#20640)ringabout2022-10-241-2/+2
| | | | | * fixes #19278; make `privateAccess` work with generic ref object * fixes
* fixes #20572 (#20585)Andreas Rumpf2022-10-171-1/+1
| | | | | * fixes #20572 * added a test case
* Fix/improve handling of forward declarations in nimsuggest (#20493)Ivan Yonchovski2022-10-061-1/+1
| | | | | | | | | | | | | | | | | * Fix/improve handling of forward declarations in nimsuggest - ideUse now works fine when invoked on the implementation - implemented ideDeclaration to make cover lsp feature textDocument/declaration - fixed performance issue related to deduplicating symbols. Now the deduplication happens after the symbols are filtered. As a alternative we might change the way cached symbols are stored(e. g. use set). - I also fixed the way globalSymbols work. Now it will sort the responses based on the match location to make sure that the results are sorted in user friendly way. * Update nimsuggest/nimsuggest.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* store full definition AST for consts, fix noRewrite (#20115)metagn2022-09-281-10/+0
| | | | | | | | | | | | | | | | | | | | | | | * continue #9582 for consts, close #9331, fix #20114 also move extractPragma to ast to pave the way for things like {.strdefine: "abc".} etc * changelog correctly * fix jsgen * update tgetimpl * fix sighashes * fix #19766, add comment about postfix * fix noRewrite LOL refs #16620 * fix changelog * fix destructors
* [nimsuggest] fix def call on identifier 2 times on the line (#20228)Ivan Yonchovski2022-08-301-1/+14
| | | | | | | - apparently TLineInfo's implementation of `==` ignores the column. After I fixed the code to use exact TLineInfo comparison I fixed several other issues hidden by that issue. - Replaced `tuple[sym, info]` with `SymInfoPair`
* Use module actual file instead of PSym.info (#19956)Ivan Yonchovski2022-07-151-12/+18
| | | After this you can do goto module from module import
* Change `styleCheck` to ignore foreign packages (#19822)quantimnot2022-07-141-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Change `styleCheck` to ignore foreign packages * Symbols from foreign packages are now ignored. * Fixed `styleCheck` violations in `compiler` package. * Added symbol ownership to custom annotation pragmas. * Minor refactors to cleanup style check callsites. * Minor internal documentation of reasons why a symbol isn't checked. Style violations were fixed in the compiler after thet were exposed by the changes. The compiler wouldn't compile otherwise. Symbol ownership for custom pragma annotations is needed for checking the annotation's style. A NPE was raised otherwise. Fixes #10201 See also nim-lang/RFCs#456 * Fix a misunderstanding about excluding field style checks I had refactored the callsites of `styleCheckUse` to apply the DRY principle, but I misunderstood the field access handling in a template as a general case. This corrects it. * Fix some `styleCheck` violations in `compiler/evalffi` The violations were exposed in CI when the compiler was built with libffi. * Removed some uneeded transitionary code * Add changelog entry Co-authored-by: quantimnot <quantimnot@users.noreply.github.com>
* Initial implementation of nimsuggest v3 (#19826)Ivan Yonchovski2022-06-131-5/+7
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Initial implementation of nimsuggest v3 Rework `nimsuggest` to use caching to make usage of ide commands more efficient. Previously, all commands no matter what the state of the process is were causing clean build. In the context of Language Server Protocol(LSP) and lsp clients this was causing perf issues and overall instability. Overall, the goal of v3 is to fit to LSP Server needs - added two new commands: - `recompile` to do clean compilation - `changed` which can be used by the IDEs to notify that a particular file has been changed. The later can be utilized when using LSP file watches. - `globalSymbols` - searching global references - added `segfaults` dependency to allow fallback to clean build when incremental fails. I wish the error to be propagated to the client so we can work on fixing the incremental build failures (typically hitting pointer) - more efficient rebuild flow. ATM incremental rebuild is triggered when the command needs that(i. e. it is global) while the commands that work on the current source rebuild only it Things missing in this PR: - Documentation - Extensive unit testing. Although functional I still see this more as a POC that this approach can work. Next steps: - Implement `sug` request. - Rework/extend the protocol to allow better client/server communication. Ideally we will need push events, diagnostics should be restructored to allow per file notifications, etc. - implement v3 test suite. - better logging * Add tests for v3 and implement ideSug * Remove typeInstCache/procInstCache cleanup * Add ideChkFile command * Avoid contains call when adding symbol info * Remove log * Remove segfaults
* get rid of the warnings during bootstrapping (#18741)Miran2021-08-241-1/+1
| | | | | * fix bootstrapping hints and warnings * revert removals in ccgtypes
* followup #18362: make `UnusedImport` work robustly (#18366)Timothee Cour2021-06-271-2/+3
| | | | * warnDuplicateModuleImport => hintDuplicateModuleImport * improve DuplicateModuleImport msg, add test
* fix https://github.com/nim-lang/RFCs/issues/311 remove unary slice (#16714)Timothee Cour2021-04-191-1/+1
|
* privateAccess now works with ref | ptr (#17760)Timothee Cour2021-04-191-1/+3
|
* `import foo {.all.}` reboot (#17706)Timothee Cour2021-04-161-4/+9
|
* nimsuggest prioritize non-deprecated suggestions (#16816)Saem Ghani2021-01-291-15/+27
| | | | | | | | | | | * penalizes the quality score of deprecated symbols * uses quality more pervasively in order to reflect deprecation impact * impacts both sug and con additional notes: * linux i386 CI was failing * this is because the suggested results differ slightly in their sort * 64 bit tables.getOrDefault:441 was returned, while 32 bit returned 422 * for now simply removing the last line is good enough
* fixed nim-lang/nimsuggest#48 type aware sug (#16814)Saem Ghani2021-01-251-2/+7
| | | | * suggesting identifiers accounts context over scope (distance) * key takeaway: context fit is prioritized over a heuristics like scope
* fixes nim-lang/nimsuggest#103 con dot exprs (#16657)Saem Ghani2021-01-121-0/+1
| | | | - con calls for dot exprs now returns results - discovered an issue with dot expr results -- documented
* fixed nim-lang/nimsuggest#82 pure enum field sug (#16676)Saem Ghani2021-01-111-10/+11
| | | | - previous code wasn't account for tyEnum being wrapped in tyTypeDesc - now pure enum fields are suggested
* IC: next steps (#16550)Andreas Rumpf2021-01-071-38/+39
| | | | | | | | | | | | | | | | | | * cleanups * ast.nim: cleanups * IC: no more sym.tab field, stored externally in the module graph * nimble compiles again * rodfiles: store bitwidth of integers and the endianness in the cookie because we serialize 'int' directly * rodfiles: added compilerproc and export sections * rodfiles: added all the missing sections * rodfiles: track the missing information * IC: architecture for lazy loading of proc bodies * make tests green again * completed the lazy loading of proc bodies * symbol lookup integration, part 1 * symbol lookup integration, part 2 * symbol lookup integration, part 3 * make tcompilerapi work again * rodfiles: fixed config change handling
* fixes nim-lang/nimsuggest#119 outline includes (#16608)Saem Ghani2021-01-061-3/+13
| | | | | | nimsuggest outline should account for includes, now it does: - the module prefix will be of the module doing the including - the filename will be of the module that was included - adds a test case for it
* refactorings to prepare the compiler for IC (#15935)Andreas Rumpf2020-12-171-33/+17
| | | | | | | | | | | | | | * added ic specific Nim code; WIP * make the symbol import mechanism lazy; WIP * ensure that modules can be imported multiple times * ambiguity checking * handle converters and TR macros properly * make 'enum' test category green again * special logic for semi-pure enums * makes nimsuggest tests green again * fixes nimdata * makes nimpy green again * makes more important packages work
* suggest: try to find the implementation of a symbol when def is used (#15555)alaviss2020-10-141-7/+15
| | | | | * suggest: try to find the implementation of a symbol when def is used * suggest: return all declarations of the symbol on `def`
* Big compiler Cleanup (#14777)Clyybber2020-08-281-1/+1
|
* compiler: minor code cleanupsAraq2020-07-271-1/+1
|
* fix #11009 (#14935)flywind2020-07-091-1/+6
|
* Clean out oldast (#14837)Juan Carlos2020-06-301-4/+1
| | | | * Clean out old Deprecated CLI switch * Update to remove --oldast CLI option
* compiler/suggest: highlight squashed operators (#11796)alaviss2020-04-201-3/+7
| | | | | | The operator fetching proc is greedy, so operators such as `%*` in expression `%*{}` can't be highlighted. This commit fixes that.
* make `usage of foo is a user-defined error` more informative (#13833)Timothee Cour2020-04-011-3/+5
|
* fix .deprecated. object typedef crash (#13643)Andy Davidoff2020-03-161-3/+5
| | | | | * fix .deprecated. object typedef crash * fixup a test that i don't understand * disable the test rather than debug ci
* Cosmetic compiler cleanup (#12718)Clyybber2019-11-281-30/+28
| | | | | | | | | | | | | | | | | | * Cleanup compiler code base * Unify add calls * Unify len invocations * Unify range operators * Fix oversight * Remove {.procvar.} pragma * initCandidate -> newCandidate where reasonable * Unify safeLen calls