-
Notifications
You must be signed in to change notification settings - Fork 11
Migrate to nwn_script_comp
#77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: migrate-nwnsc-to-nwn-script-compiler
Are you sure you want to change the base?
Changes from all commits
cefe8d0
4977c1f
025ff44
1a7e9cf
7b66b61
21c357a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,20 +25,27 @@ export default class DiagnoticsProvider extends Provider { | |
|
|
||
| private generateDiagnostics(uris: string[], files: FilesDiagnostics, severity: DiagnosticSeverity) { | ||
| return (line: string) => { | ||
| const uri = uris.find((uri) => basename(fileURLToPath(uri)) === lineFilename.exec(line)![2]); | ||
|
|
||
| if (uri) { | ||
| const linePosition = Number(lineNumber.exec(line)![1]) - 1; | ||
| const diagnostic = { | ||
| severity, | ||
| range: { | ||
| start: { line: linePosition, character: 0 }, | ||
| end: { line: linePosition, character: Number.MAX_VALUE }, | ||
| }, | ||
| message: lineMessage.exec(line)![2].trim(), | ||
| }; | ||
|
|
||
| files[uri].push(diagnostic); | ||
| const lineFilenameMatch = lineFilename.exec(line); | ||
| if (lineFilenameMatch) { | ||
| const reportedFileName = lineFilenameMatch[2]; | ||
| const uri = uris.find((uri) => basename(fileURLToPath(uri)) === reportedFileName); | ||
| if (uri) { | ||
| const lineNumberMatch = lineNumber.exec(line); | ||
| const lineMessageMatch = lineMessage.exec(line); | ||
| if (lineNumberMatch && lineMessageMatch) { | ||
| const linePosition = Number(lineNumberMatch[1]) - 1; | ||
| const diagnostic = { | ||
| severity, | ||
| range: { | ||
| start: { line: linePosition, character: 0 }, | ||
| end: { line: linePosition, character: Number.MAX_VALUE }, | ||
| }, | ||
| message: lineMessageMatch[2].trim(), | ||
| }; | ||
|
|
||
| files[uri].push(diagnostic); | ||
| } | ||
| } | ||
| } | ||
| }; | ||
| } | ||
|
|
@@ -101,7 +108,10 @@ export default class DiagnoticsProvider extends Provider { | |
| // The compiler command: | ||
| // - y; continue on error | ||
| // - s; dry run | ||
| const args = ["-y", "-s"]; | ||
| // - n; no entry point required (for include files) | ||
| // - E; collect and report all errors (not just the first) | ||
| // Note: -E requires compiler binary with ABI v2+ | ||
| const args = ["-y", "-s", "-n", "-E"]; | ||
| if (Boolean(nwnHome)) { | ||
| args.push("--userdirectory"); | ||
| args.push(`"${nwnHome}"`); | ||
|
|
@@ -114,12 +124,25 @@ export default class DiagnoticsProvider extends Provider { | |
| } else if (verbose) { | ||
| this.server.logger.info("Trying to resolve Neverwinter Nights installation directory automatically."); | ||
| } | ||
| if (children.length > 0) { | ||
| // 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))); | ||
| } | ||
| }); | ||
|
Comment on lines
+127
to
+134
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we sure this doesn't cause performance issues?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's obviously less performant, but the hit is moderate. If we wanted to optimize this, I could do some caching on 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.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll try and see if I can walk the tree of children to minimize it and not mess up compilation
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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).
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's try it this way then, thank you for validating. |
||
| // Also add the compiled file's own directory | ||
| allDirs.add(dirname(fileURLToPath(uri))); | ||
| if (allDirs.size > 0) { | ||
| args.push("--dirs"); | ||
| args.push(`"${[...new Set(uris.map((uri) => dirname(fileURLToPath(uri))))].join(",")}"`); | ||
| args.push(`"${[...allDirs].join(",")}"`); | ||
| } | ||
|
|
||
| const filePath = fileURLToPath(uri); | ||
| this.server.logger.info(`Compiling file: ${filePath}`); | ||
| args.push("-c"); | ||
| args.push(`"${fileURLToPath(uri)}"`); | ||
| args.push(`"${filePath}"`); | ||
|
|
||
| let stdout = ""; | ||
| let stderr = ""; | ||
|
|
@@ -186,6 +209,7 @@ export default class DiagnoticsProvider extends Provider { | |
| for (const [uri, diagnostics] of Object.entries(files)) { | ||
| this.server.connection.sendDiagnostics({ uri, diagnostics }); | ||
| } | ||
|
|
||
| resolve(true); | ||
| }); | ||
| }); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.