Commit Graph

167 Commits

Author SHA1 Message Date
metagn
71de7fca9e handle explicit generic routine instantiations in sigmatch (#24010)
fixes #16376

The way the compiler handled generic proc instantiations in calls (like
`foo[int](...)`) up to this point was to instantiate `foo[int]`, create
a symbol for the instantiated proc (or a symchoice for multiple procs
excluding ones with mismatching generic param counts), then perform
overload resolution on this symbol/symchoice. The exception to this was
when the called symbol was already a symchoice node, in which case it
wasn't instantiated and overloading was called directly ([these
lines](b7b1313d21/compiler/semexprs.nim (L3366-L3371))).

This has several problems:

* Templates and macros can't create instantiated symbols, so they
couldn't participate in overloaded explicit generic instantiations,
causing the issue #16376.
* Every single proc that can be instantiated with the given generic
params is fully instantiated including the body. #9997 is about this but
isn't fixed here since the instantiation isn't in a call.

The way overload resolution handles explicit instantiations by itself is
also buggy:

* It doesn't check constraints.
* It allows only partially providing the generic parameters, which makes
sense for implicit generics, but can cause ambiguity in overloading.

Here is how this PR deals with these problems:

* Overload resolution now always handles explicit generic instantiations
in calls, in `initCandidate`, as long as the symbol resolves to a
routine symbol.
* Overload resolution now checks the generic params for constraints and
correct parameter count (ignoring implicit params). If these don't
match, the entire overload is considered as not matching and not
instantiated.
* Special error messages are added for mismatching/missing/extra generic
params. This is almost all of the diff in `semcall`.
* Procs with matching generic parameters now instantiate only the type
of the signature in overload resolution, not the proc itself, which also
works for templates and macros.

Unfortunately we can't entirely remove instantiations because overload
resolution can't handle some cases with uninstantiated types even though
it's resolved in the binding (see the last 2 blocks in
`texplicitgenerics`). There are also some instantiation issues with
default params that #24005 didn't fix but I didn't want this to become
the 3rd huge generics PR in a row so I didn't dive too deep into trying
to fix them. There is still a minor instantiation fix in `semtypinst`
though for subscripts in calls.

Additional changes:

* Overloading of `[]` wasn't documented properly, it somewhat is now
because we need to mention the limitation that it can't be done for
generic procs/types.
* Tests can now enable the new type mismatch errors with just
`-d:testsConciseTypeMismatch` in the command.

Package PRs:

- using fork for now:
[combparser](https://github.com/PMunch/combparser/pull/7) (partial
generic instantiation)
- merged: [cligen](https://github.com/c-blake/cligen/pull/233) (partial
generic instantiation but non-overloaded + template)
- merged: [neo](https://github.com/andreaferretti/neo/pull/56) (trying
to instantiate template with no generic param)
2024-09-02 18:22:20 +02:00
ringabout
0db742df7c fixes #23867; fixes #23316; rework nimsuggest for ORC (#23879)
fixes #23867
fixes #23316 


follow up https://github.com/nim-lang/Nim/pull/22805; fixes
https://github.com/nim-lang/Nim/issues/22794 in a different method
2024-07-23 16:46:49 +02:00
Juan M Gómez
1cbcbd9269 Fixes #23695: On Linux, "nimsuggest" crashes if Nim is installed in /usr/bin and the library in /usr/lib/nim (#23697)
(Not tested)
2024-06-10 16:17:02 +02:00
Juan M Gómez
c7ee16182e nimsuggest v3+ handles unknownFile (#23696) 2024-06-08 13:02:48 +02:00
Nikolay Nikolov
899ba01ccf + added nimsuggest support for exception inlay hints (#23202)
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.
2024-03-15 18:20:10 +01:00
Juan M Gómez
2081da3207 makes nimsuggest listen on localhost by default (#23351) 2024-03-04 09:58:06 +01:00
autumngray
15577043e8 Fix nimsuggest highlight for import statements (#23263)
Currently, I don't have syntax highlighting (+ no/wrong
jump-to-definition) for some import statement forms, namely:

- `import module/name/with/(slashes)`
- `import (mod) as alias`
- `import basemod/[ (sub1), (sub2) ]`

With this patch, highlight/def will work for the regions indicated by
parentheses.
2024-03-03 16:05:11 +01:00
Nikolay Nikolov
37ed8c8480 * fixed nimsuggest crash with 'Something = concept' put (erroneously) outside of a 'type' block (#23331) 2024-02-24 07:55:23 +01:00
Nikolay Nikolov
773c066634 * fixed nimsuggest crash when opening a .nim file, that contain a {.fatal: "msg".} pragma. (#23325) 2024-02-20 08:11:08 +01:00
Juan M Gómez
92c8c6d5f4 fixes nimsuggest sug doesnt return anything on first pass #23283 (#23288)
fixes #23283
2024-02-15 16:23:15 +01:00
Juan M Gómez
ae2cdcebc2 nimsuggest --ic:on compiles (#23298) 2024-02-09 18:45:01 +01:00
Juan M Gómez
6c2fca1a8b [fix] nimsuggest con sometimes doesnt return anything on first pass fixes #23281 (#23282)
fixes #23281
2024-02-05 14:33:48 +01:00
Nikolay Nikolov
18b5fb256d + show the inferred exception list (as part of the type) for functions that don't have an explicit .raises pragma (#23193) 2024-01-15 18:36:03 +01:00
Juan M Gómez
fd253a08b1 Adds info:capabilities to NimSuggest (#23134) 2023-12-29 13:47:08 +01:00
Juan M Gómez
df3c95d8af makes nimsuggest con work under v3 (#23113)
Co-authored-by: Jake Leahy <jake@leahy.dev>
2023-12-22 05:38:40 +01:00
Jake Leahy
0a7094450e Only suggest symbols that could be pragmas when typing a pragma (#23040)
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
2023-12-07 23:05:41 +01:00
Jake Leahy
b8fa789393 Fix nimsuggest def being different on proc definition/use (#23025)
Currently the documentation isn't shown when running `def` on the
definition of a proc (Which works for things like variables).
`gcsafe`/`noSideEffects` status also isn't showing up when running `def`
on the definition

Images of current behavior. After PR both look like "Usage"
**Definition**

![image](https://github.com/nim-lang/Nim/assets/19339842/bf75ff0b-9a96-49e5-bf8a-d2c503efa784)
**Usage**

![image](https://github.com/nim-lang/Nim/assets/19339842/15ea3ebf-64e1-48f5-9233-22605183825f)


Issue was the symbol getting passed too early to nimsuggest so it didn't
have all that info, now gets passed once proc is fully semmed
2023-12-04 07:15:16 +01:00
Jake Leahy
c31bbb07fb Register declaration of enum field has a use (#22990)
Currently when using `use` with nimsuggest on an enum field, it doesn't
return the definition of the field.

Breaks renaming in IDEs since it will replace all the usages, but not
the declaration
2023-11-27 22:08:05 +01:00
Nikolay Nikolov
502a4486ae nimsuggest: Added optional command line option '--clientProcessId:XXX' (#22969)
When it is specified, the nimsuggest instance monitors whether this
process is still alive. In case it's found to be dead, nimsuggest shuts
itself down. Currently only implemented on POSIX and Windows platforms.
The switch is silently ignored on other platforms. Note that the Nim
language server should still try to shut down its child nimsuggest
processes. This switch just adds extra protection against crashing Nim
language server and gets rid of the remaining nimsuggest processes,
which consume memory and system resources.
2023-11-24 19:55:53 +01:00
Jake Leahy
81c0513644 Don't provide suggestions for enum fields (#22959)
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>
2023-11-20 21:12:54 +01:00
Nikolay Nikolov
4fc0027b57 Introduced version 4 of the NimSuggest protocol. The InlayHints feature made V4 or later only. (#22953)
Since nimsuggest now has a protocol version support detection via
`--info:protocolVer`, the InlayHints feature can be moved to protocol
V4. This way, the Nim language server can detect the nimsuggest version
and avoid sending unsupported `InlayHints` commands to older nimsuggest
versions. Related nim language server PR:
https://github.com/nim-lang/langserver/pull/60
2023-11-18 16:21:59 +01:00
Nikolay Nikolov
3680200df4 nimsuggest: Instead of checking for protocol version 3 exactly, check for 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.
2023-11-15 18:41:58 +01:00
Nikolay Nikolov
d0cc02dfc4 Added new command line option --info:X to nimsuggest for obtaining information. (#22940)
`--info:protocolVer` returns the highest nimsuggest protocol version
that is supported (currently, it's version 3).
`--info:nimVer` returns the Nim compiler version that nimsuggest uses
internally.

Note that you can obtain the Nim compiler version via `nimsuggest -v`,
but that requires parsing the output, which looks like this:

```
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2023-11-14
Copyright (c) 2006-2023 by Andreas Rumpf

git hash: 47ddfeca5247dce992becd734d1ae44e621207b8
active boot switches: -d:release -d:danger --gc:markAndSweep
```

`--info:nimVer` will return just:

```
2.1.1
```
2023-11-15 15:10:10 +01:00
Nikolay Nikolov
f5bbdaf906 Inlay hints for types of consts (#22916)
This adds inlay hint support for the types of consts.
2023-11-07 11:25:13 +01:00
Nikolay Nikolov
3f2b9c8bcf Inlay hints support (#22896)
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>
2023-11-04 08:51:09 +01:00
Pylgos
db36765afd nimsuggest: Clear generic inst cache before partial recompilation (#22783)
fixes #19371
fixes #21093
fixes #22119
2023-10-03 10:22:31 +02:00
Pylgos
48da472dd2 fix #22448 Remove structuredErrorHook temporary in tryConstExpr (#22450)
* fix #22448

* add test
2023-08-11 18:23:09 +02:00
Jake Leahy
1b132ddaa2 Fix nimsuggest not showing suggestions for imported tuples (#22241)
* 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
2023-07-10 08:34:10 +02:00
Ivan Yonchovski
2bb7277a61 Create compiler and nimsuggest packages (#22118)
I have tested it locally with the following in my local packages_official.json

```
  {
    "name": "compiler",
    "url": "https://github.com/yyoncho/Nim.git/?subdir=compiler",
    "method": "git",
    "tags": [
      "library",
      "compiler"
    ],
    "description": "Package providing the Nim compiler binaries plus all its source files that can be used as a library",
    "license": "MIT",
    "web": "https://github.com/nim-lang/Nim"
  },
  {
    "name": "nimsuggest",
    "url": "https://github.com/yyoncho/Nim.git/?nimsuggest=compiler",
    "method": "git",
    "tags": [
      "library",
      "compiler"
    ],
    "description": "Package providing the Nim compiler binaries plus all its source files that can be used as a library",
    "license": "MIT",
    "web": "https://github.com/nim-lang/Nim"
  },
```

Then `nimble install compiler`, `nimble install nimsuggest` work as expected.
2023-06-18 16:06:14 +02:00
Juan Carlos
fa5e7dc44a Improve nimsuggest (#21825)
Small improvement for nimsuggest
2023-05-11 10:49:19 +02:00
ringabout
afc30ca879 fixes #19863; move sha1, md5 to nimble packages for 2.0 (#21702)
* move sha1, md5 to nimble packages

* boot the compiler

* fixes tests

* build the documentation

* fixes docs

* lol, I forgot koch.nim

* add `nimHasChecksums` define

* clone checksums but maybe copying is better

* bump nimble hash

* use ChecksumsStableCommit

* fixes tests

* deprecate them

* fixes paths

* fixes koch
2023-05-02 10:49:17 +02:00
Peter Munch-Ellingsen
c155e20796 Fix infinite recursion introduced in 7031ea6 [backport 1.6] (#21555)
Fix infinite recursion introduced in 7031ea6
2023-03-20 22:43:42 +01:00
ringabout
d51a392149 replaces implicit passes array registed at runtime with explicit function 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
2023-03-03 07:36:38 +01:00
ringabout
38f876dd48 fixes #19795; fixes #11852; fixes #19974; remove parsing pipeline, Nim now parses the whole module at one time (#21379)
* fixes #19795; remove parse pipeline

* isScript

* fixes nimscriptapi

* don't touch reorder

* check script

* fixes tests

* it seems implicit imports of system cause troubles

* access the first child of `nkStmtList`

* ignore comments

* minor messages

* perhaps increases hloLoopDetector

* the module is a stmtList, which changes the errors

* fixes nimdoc

* fixes tlinter

* fixes nim  secret tests

* fixes arc_misc

* fixes nim secret tests again

* safe; fixes one more test

* GlobalError is the root cause too

* fixes parsing errors

* put emit types to the cfsForwardTypes section

* fixes #11852; `{.push checks:off}` now works in procs

* disable navigator

* fixes nimdoc

* add tests for JS

* fixes nimsuggest
2023-02-22 20:34:20 +01:00
Ivan Yonchovski
7031ea65cd Implemented basic macro expand functionality (#20579)
* 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
2023-01-27 07:11:30 +01:00
Jake Leahy
3d5dbf8f96 Fix nimsuggest not suggesting fields in when theres static parameters (#21189)
Don't check against empty arguments

Add test case
2022-12-28 07:35:11 +01:00
Jake Leahy
b0a850adbf Nimsuggest now defines the backends symbol (#21083)
* Add testcase

* Define the backend symbol

* Remove unneeded whitespace
2022-12-12 22:19:02 +01:00
metagn
555c5ed1a7 fix bugs with dot & call operators [backport] (#20931)
* better error messages for dot operators [backport]

fixes #13063

* also fixes #7777

* fix #6981 and #9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements
2022-11-28 21:33:02 +01:00
ringabout
e03a178bff rename std/threads to std/typedthreads (#20850)
* rename `std/threads` to `std/oldthreads`

* fixes tests

* rename to `typedthreads`

* changelog
2022-11-16 16:35:20 +01:00
Ikko Ashimine
f0400eef68 Fix typo in nimsuggest.nim (#20767)
becase -> because
2022-11-05 20:32:28 +01:00
ringabout
75ece74bdd fixes #20526; use nimPreviewSlimSystem for documentation build (#20714)
* fixes #20526; use `nimPreviewSlimSystem` for `koch docs`

* fixes documentation errors

* fixes remaning issues
2022-11-01 12:53:14 +01:00
ringabout
e1ddd2d524 put std/threads under the umbrella of nimPreviewSlimSystem (#20711)
* put `std/threads` under the umbrella of `nimPreviewSlimSystem`

* add changelog

* fixes tests

* fixes tests again

* fixes tests
2022-10-31 06:36:50 +01:00
ringabout
1e15f975b8 fixes #19162; enable strictEffects for v2 (#19380)
* enable stricteffects
* add gcsafe
* fix tests
* use func
* fixes pegs tests
* explicitly mark repr related procs with noSideEffect
* add nimLegacyEffects
* change URL
* fixes docopt
* add `raises: []` to repr
* fixes weave
* fixes nimyaml
* fixes glob
* fixes parsetoml
* Apply suggestions from code review
* Update testament/important_packages.nim
* add legacy:laxEffects
2022-10-15 14:07:40 +02:00
ringabout
5602183234 'lock levels' are deprecated, now a noop (#20539)
* 'lock levels' are deprecated, now a noop

* fixes tests
2022-10-11 09:17:09 +02:00
Ivan Yonchovski
7caa037936 Fix/improve handling of forward declarations in nimsuggest (#20493)
* 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>
2022-10-06 07:18:46 +02:00
metagn
919a889ba8 moderate system cleanup & refactor (#20355)
* system refactor, move out 600 lines

* compilation, slice, backwardsindex, misc_num moved out of system
* some procs/types moved into arithmetics, basic_types
* system no longer depends on syncio
* some procs moved around to fit with their surroundings

* make exceptions an import, old ops to misc_num

* move instantiationInfo back

* move back nim version, fix windows echo

* include compilation

* better docs for imported modules, fix unsigned ops

also remove ze, ze64, toU8, toU16, toU32 with nimPreviewSlimSystem

* fix terminal

* workaround IC test & weird csize bug, changelog

* move NimMajor etc back to compilation, rebase for CI

* try ic fix

* form single `indices`, slim out TaintedString, try fix IC

* fix CI, update changelog, addQuitProc

* fix CI

* try fix CI

* actually fix CI finally hopefully

* Update lib/system/compilation.nim

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>

* update kochdocs

* hopefully fix csize uses for slimsystem

* fix tquit

Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
2022-09-28 15:28:45 -04:00
ringabout
7739e23420 defaults to ORC (#19972)
* defaults to Orc

* bootstrap using refc

* use gc

* init orc defines

* unregister orc

* fix gc

* fix commands

* add prepareMutation for orc

* enable deepcopy for orc

* prepareMutation

* more fixes

* some cases

* bug #20081

* partial fixes

* partial fixes

* fixes command line

* more fixes

* build Nim with refc

* use gc

* more fixes

* rstore

* orc doesn't support threadpool

* more shallowCopy

* more fixes

* fixes unsafeNew

* workarounds

* small

* more fixes

* fixes some megatest

* tcodegenbugs1 refc

* fxies megatest

* build nimble with refc

* workaround tensordsl tests

* replace shallowCopy with move

* fixes action

* workaround

* add todo

* fixes important packages

* unpublic unregisterArcOrc

* fixes cpp

* enable windows

Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
2022-09-23 13:05:05 +02:00
ringabout
f540fd5cde Partially Revert "Change nim's nimble files to make it installable" (#20296)
add nimsuggest.nimble back
2022-09-02 19:05:23 +02:00
Ivan Yonchovski
fb2773411e Change nim's nimble files to make it installable (#20179)
- needs #20168 to make the stuff working

I went for this minimal solution because it seems like `compiler.nimble` and
`nimsuggest.nimble` are not in use

Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
2022-08-31 15:06:27 -04:00
Ivan Yonchovski
d4c0d35b32 [nimsuggest] fix def call on identifier 2 times on the line (#20228)
- 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`
2022-08-30 21:02:15 +02:00