Migrate to nwn_script_comp#77
Migrate to nwn_script_comp#77cgtudor wants to merge 6 commits intoPhilippeChab:migrate-nwnsc-to-nwn-script-compilerfrom
nwn_script_comp#77Conversation
|
Note about the last commit. An improvement to the compiler to get parity (hopefully) with |
|
| Platform | Status | Issue |
|---|---|---|
| Windows | ✅ Works | powershell.exe exists |
| Linux | ❌ BROKEN | powershell.exe doesn't exist |
| macOS | ❌ BROKEN | powershell.exe doesn't exist |
This will completely break the diagnostics feature on non-Windows platforms.
Why This Matters
- The project provides separate compiler binaries for Linux/macOS (lines 56-65)
- The code already has OS detection logic
- Many NWN modders use Linux servers
Recommended Fix
Option 1 (simplest): Revert to { shell: true }
const child = spawn(join(__dirname, this.getExecutablePath(os)), args, { shell: true });Option 2: Use OS-specific shells
const shell = type() === OS.windows ? 'powershell.exe' : true;
const child = spawn(join(__dirname, this.getExecutablePath(os)), args, { shell });Option 3 (best): Fix argument escaping without relying on PowerShell-specific behavior
If you encountered quoting issues on Windows, we should solve that without breaking other platforms.
Additional Issues FoundAfter deeper review, I've identified several more issues beyond the PowerShell problem: 🔴 CRITICAL: Linux/macOS Binaries Not UpdatedProblem: Only the Windows binary was updated in this PR, but the code uses new flags ( Evidence:
Impact: The diagnostics will fail on Linux/macOS because the compiler won't recognize the const args = ["-y", "-s", "-n", "-E"]; // Lines 110The comment even states: Fix Required: Update Linux and macOS binaries to match the Windows version, or wait for neverwinter.nim PR #152 to be merged and released.
|
| Issue | Severity | Platforms Affected |
|---|---|---|
| PowerShell hardcoded | 🔴 Critical | Linux, macOS |
| Missing binary updates | 🔴 Critical | Linux, macOS |
| Unsafe regex access | All (if malformed compiler output) | |
| Non-deterministic file resolution | All (if duplicate filenames) |
Recommendation: Address the two critical cross-platform issues before merging.
… exiting early on the first one (so everything is underlined instead of having to solve one, save, solve the next)
|
Everything addressed! One comment was on a bit that's a hack for TDN and so I removed it, but I will make a new PR with a version of that which is generalized and behind an option because we need it and maybe others do as well. |
| // Collect directories from ALL indexed documents so the compiler can | ||
| // resolve the full transitive include chain, not just direct children. | ||
| const allDirs: Set<string> = new Set(); | ||
| this.server.documentsCollection.forEach((doc) => { | ||
| if (doc.uri && doc.uri.startsWith("file://")) { | ||
| allDirs.add(dirname(fileURLToPath(doc.uri))); | ||
| } | ||
| }); |
There was a problem hiding this comment.
Are we sure this doesn't cause performance issues?
There was a problem hiding this comment.
It's obviously less performant, but the hit is moderate.
Even with hundreds of scripts, even >1k, we are talking about an O(n) iteration over them on each file save and each queued document. In practice so far, for me, it's not been noticeable. The start-up indexing period takes the biggest hit but it was already slow and the difference is not that big.
If we wanted to optimize this, I could do some caching on ServerManager and invalidate it only when documents are added/removed so we don't have to recompute on every publish call.
However, there is a potential performance hit here that's bigger, and that's the amount of directories we pass to "--dirs", it might affect compilation time if the dirs list is very large. I had to do this to get the new compiler to work, but there might be a better way. I'll have a think.
There was a problem hiding this comment.
I'll try and see if I can walk the tree of children to minimize it and not mess up compilation
There was a problem hiding this comment.
Yea, we can't as I remembered.
We can't narrow this to just transitive children from getChildren() because the tokenizer's include tracking may be incomplete compared to what the compiler actually resolves (e.g. deep/nested transitive includes, conditional includes, or files the tokenizer hasn't fully parsed).
There was a problem hiding this comment.
Let's try it this way then, thank you for validating.
|
Alright, once the upstream compiler changes are merged, we can go forward. |
This is built on top of the existing PR and it adds support for the new compiler by first having modified the compiler to accept the
-nflag in order to allow it to parse include files (no entry points) without trying to produce an.ncsout of them, just for validation.The commit history is a bit messy as I first tried a hacky way of doing it, which turned out to be quite problematic. This, however, I've tested locally to great success.
Caveat: While I did make a PR to
neverwinter.nimwith my addition, it's not yet merged to the main repo. You can see the changes I made to it here, though.