Skip to content

Commit

Permalink
Implements entryPoints opt-in. (#1228)
Browse files Browse the repository at this point in the history
A list of relative paths to nim files that will be used by the `nimlangserver` as project entry points.
  • Loading branch information
jmgomez authored Jun 26, 2024
1 parent ed0b6ee commit 78debc8
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 3 deletions.
2 changes: 2 additions & 0 deletions nimble-guide/docs/nimble-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
* `backend` - Specifies the backend which will be used to build the files
listed in `bin`. Possible values include: `c`, `cc`, `cpp`, `objc`,
`js`.
* ``paths`` - A list of relative paths that will be expanded on `nimble.paths` and the search paths options to the compiler.
* ``entryPoints`` - A list of relative paths to nim files that will be used by the `nimlangserver` as project entry points. Useful for test files like `tall.nim`
**Default**: `c`.


Expand Down
9 changes: 9 additions & 0 deletions src/nimble.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1165,6 +1165,14 @@ proc getNimDir(options: Options): string =
else:
options.nimBin.parentDir

proc getEntryPoints(pkgInfo: PackageInfo, options: Options): seq[string] =
## Returns the entry points for a package.
## This is useful for tools like the lsp.
let main = pkgInfo.srcDir / pkgInfo.basicInfo.name & ".nim"
result.add main
for entry in pkgInfo.entryPoints:
result.add if entry.endsWith(".nim"): entry else: entry & ".nim"

proc dump(options: Options) =
cli.setSuppressMessages(true)
let p = getPackageByPattern(options.action.projName, options)
Expand Down Expand Up @@ -1216,6 +1224,7 @@ proc dump(options: Options) =
fn "backend", p.backend
fn "paths", p.paths
fn "nimDir", getNimDir(options)
fn "entryPoints", p.getEntryPoints(options)
if json:
s = j.pretty
echo s
Expand Down
3 changes: 2 additions & 1 deletion src/nimblepkg/nimscriptapi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var
backend*: string ## The package's backend.

skipDirs*, skipFiles*, skipExt*, installDirs*, installFiles*,
installExt*, bin*, paths*: seq[string] = @[] ## Nimble metadata.
installExt*, bin*, paths*, entryPoints*: seq[string] = @[] ## Nimble metadata.
requiresData*: seq[string] = @[] ## The package's dependencies.
taskRequiresData*: Table[string, seq[string]] ## Task dependencies
foreignDeps*: seq[string] = @[] ## The foreign dependencies. Only
Expand Down Expand Up @@ -142,6 +142,7 @@ proc printPkgInfo(): string =
printSeqIfLen installFiles
printSeqIfLen installExt
printSeqIfLen paths
printSeqIfLen entryPoints
printSeqIfLen bin
printSeqIfLen "nimbleTasks", nimbleTasks.unzip()[0]
printSeqIfLen beforeHooks
Expand Down
1 change: 1 addition & 0 deletions src/nimblepkg/packageinfotypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type
metaData*: PackageMetaData
isLink*: bool
paths*: seq[string]
entryPoints*: seq[string] #useful for tools like the lsp.

Package* = object ## Definition of package from packages.json.
# Required fields in a package.
Expand Down
2 changes: 2 additions & 0 deletions src/nimblepkg/packageparser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ proc readPackageInfoFromNimble(path: string; result: var PackageInfo) =
result.postHooks.incl(i.normalize)
of "paths":
result.paths.add(ev.value.multiSplit)
of "entrypoints":
result.entryPoints.add(ev.value.multiSplit)
else:
raise nimbleError("Invalid field: " & ev.key)
of "deps", "dependencies":
Expand Down
3 changes: 2 additions & 1 deletion tests/testdump/testdump.nimble
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ description = "Test package for dump command"
version = "0.1.0"
author = "nigredo-tori"
license = "BSD"
paths = @["path"]
paths = @["path"]
entryPoints = @["entrypoint.nim"]
7 changes: 6 additions & 1 deletion tests/tnimbledump.nim
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ srcDir: ""
backend: "c"
paths: "path"
nimDir: {nimDir.escape}
entryPoints: "testdump.nim, entrypoint.nim"
"""
let (outp, exitCode) = execNimble("dump", "--ini", "testdump")
check: exitCode == 0
Expand Down Expand Up @@ -92,7 +93,11 @@ nimDir: {nimDir.escape}
"paths": [
"path"
],
"nimDir": {nimDir.escape}
"nimDir": {nimDir.escape},
"entryPoints": [
"testdump.nim",
"entrypoint.nim"
]
}}
"""
let (outp, exitCode) = execNimble("dump", "--json", "testdump")
Expand Down

0 comments on commit 78debc8

Please sign in to comment.