Skip to content

Commit 78debc8

Browse files
authored
Implements entryPoints opt-in. (#1228)
A list of relative paths to nim files that will be used by the `nimlangserver` as project entry points.
1 parent ed0b6ee commit 78debc8

File tree

7 files changed

+24
-3
lines changed

7 files changed

+24
-3
lines changed

nimble-guide/docs/nimble-reference.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@
5454
* `backend` - Specifies the backend which will be used to build the files
5555
listed in `bin`. Possible values include: `c`, `cc`, `cpp`, `objc`,
5656
`js`.
57+
* ``paths`` - A list of relative paths that will be expanded on `nimble.paths` and the search paths options to the compiler.
58+
* ``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`
5759
**Default**: `c`.
5860

5961

src/nimble.nim

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,6 +1165,14 @@ proc getNimDir(options: Options): string =
11651165
else:
11661166
options.nimBin.parentDir
11671167

1168+
proc getEntryPoints(pkgInfo: PackageInfo, options: Options): seq[string] =
1169+
## Returns the entry points for a package.
1170+
## This is useful for tools like the lsp.
1171+
let main = pkgInfo.srcDir / pkgInfo.basicInfo.name & ".nim"
1172+
result.add main
1173+
for entry in pkgInfo.entryPoints:
1174+
result.add if entry.endsWith(".nim"): entry else: entry & ".nim"
1175+
11681176
proc dump(options: Options) =
11691177
cli.setSuppressMessages(true)
11701178
let p = getPackageByPattern(options.action.projName, options)
@@ -1216,6 +1224,7 @@ proc dump(options: Options) =
12161224
fn "backend", p.backend
12171225
fn "paths", p.paths
12181226
fn "nimDir", getNimDir(options)
1227+
fn "entryPoints", p.getEntryPoints(options)
12191228
if json:
12201229
s = j.pretty
12211230
echo s

src/nimblepkg/nimscriptapi.nim

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var
2626
backend*: string ## The package's backend.
2727

2828
skipDirs*, skipFiles*, skipExt*, installDirs*, installFiles*,
29-
installExt*, bin*, paths*: seq[string] = @[] ## Nimble metadata.
29+
installExt*, bin*, paths*, entryPoints*: seq[string] = @[] ## Nimble metadata.
3030
requiresData*: seq[string] = @[] ## The package's dependencies.
3131
taskRequiresData*: Table[string, seq[string]] ## Task dependencies
3232
foreignDeps*: seq[string] = @[] ## The foreign dependencies. Only
@@ -142,6 +142,7 @@ proc printPkgInfo(): string =
142142
printSeqIfLen installFiles
143143
printSeqIfLen installExt
144144
printSeqIfLen paths
145+
printSeqIfLen entryPoints
145146
printSeqIfLen bin
146147
printSeqIfLen "nimbleTasks", nimbleTasks.unzip()[0]
147148
printSeqIfLen beforeHooks

src/nimblepkg/packageinfotypes.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type
7070
metaData*: PackageMetaData
7171
isLink*: bool
7272
paths*: seq[string]
73+
entryPoints*: seq[string] #useful for tools like the lsp.
7374

7475
Package* = object ## Definition of package from packages.json.
7576
# Required fields in a package.

src/nimblepkg/packageparser.nim

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,8 @@ proc readPackageInfoFromNimble(path: string; result: var PackageInfo) =
273273
result.postHooks.incl(i.normalize)
274274
of "paths":
275275
result.paths.add(ev.value.multiSplit)
276+
of "entrypoints":
277+
result.entryPoints.add(ev.value.multiSplit)
276278
else:
277279
raise nimbleError("Invalid field: " & ev.key)
278280
of "deps", "dependencies":

tests/testdump/testdump.nimble

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ description = "Test package for dump command"
22
version = "0.1.0"
33
author = "nigredo-tori"
44
license = "BSD"
5-
paths = @["path"]
5+
paths = @["path"]
6+
entryPoints = @["entrypoint.nim"]

tests/tnimbledump.nim

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ srcDir: ""
6161
backend: "c"
6262
paths: "path"
6363
nimDir: {nimDir.escape}
64+
entryPoints: "testdump.nim, entrypoint.nim"
6465
"""
6566
let (outp, exitCode) = execNimble("dump", "--ini", "testdump")
6667
check: exitCode == 0
@@ -92,7 +93,11 @@ nimDir: {nimDir.escape}
9293
"paths": [
9394
"path"
9495
],
95-
"nimDir": {nimDir.escape}
96+
"nimDir": {nimDir.escape},
97+
"entryPoints": [
98+
"testdump.nim",
99+
"entrypoint.nim"
100+
]
96101
}}
97102
"""
98103
let (outp, exitCode) = execNimble("dump", "--json", "testdump")

0 commit comments

Comments
 (0)