Port parseCommandLine, readConfigFile, and parseJsonConfigFileContent - #4888
Conversation
There was a problem hiding this comment.
Pull request overview
Ports command-line and JSON config parsing APIs for the native-preview API, advancing #4830.
Changes:
- Adds
parseCommandLine,readConfigFile, andparseJsonConfigFileContent. - Adds watch-option, raw-config, and diagnostic serialization.
- Expands Go and TypeScript API coverage.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
testdata/baselines/reference/tsc/showConfig/Show-TSConfig-with-compileOnSave-and-more.js |
Updates compileOnSave baseline. |
internal/tsoptions/tsconfigparsing.go |
Parses and merges watch options and JSON values. |
internal/tsoptions/tsconfigparsing_test.go |
Tests JSON representations and watch options. |
internal/tsoptions/declswatch.go |
Exposes the watch-option map. |
internal/tsoptions/commandlineparser.go |
Adds API-compatible parsing and response-file safeguards. |
internal/tsoptions/commandlineparser_test.go |
Tests response-file parsing. |
internal/api/session.go |
Handles the new API requests. |
internal/api/proto.go |
Defines request and response protocol structures. |
internal/api/proto_test.go |
Tests ordered JSON decoding. |
_packages/native-preview/test/sync/api.test.ts |
Adds synchronous API integration tests. |
_packages/native-preview/test/async/api.test.ts |
Adds asynchronous API integration tests. |
_packages/native-preview/src/api/sync/types.ts |
Updates generated synchronous types. |
_packages/native-preview/src/api/sync/api.ts |
Exposes synchronous parsing APIs. |
_packages/native-preview/src/api/proto.ts |
Defines client protocol result types. |
_packages/native-preview/src/api/async/types.ts |
Shares diagnostic protocol types. |
_packages/native-preview/src/api/async/api.ts |
Exposes asynchronous parsing APIs. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
internal/tsoptions/tsconfigparsing.go:1526
- This leaves
CompileOnSavenil when the property is absent or invalid, so the API omitscompileOnSaveand clients observeundefined. The referenceparseJsonConfigFileContentalways returns a boolean using!!raw.compileOnSave(commandLineParser.ts:3106), which isfalsein these cases. Initialize the result to false and always return its pointer from config parsing.
var compileOnSave *bool
if raw, ok := parsedConfig.raw.(*collections.OrderedMap[string, any]); ok {
if value, ok := raw.GetOrZero("compileOnSave").(bool); ok {
compileOnSave = &value
}
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
internal/tsoptions/tsconfigparsing.go:1531
- The reference
parseJsonConfigFileContentalways returns a booleancompileOnSave(!!raw.compileOnSave), includingfalsewhen the property is absent or invalid. Leaving this pointer nil causes the IPC response to omit the field, so callers receiveundefinedinstead of the expectedfalse. Initialize the result to false and overwrite it when a boolean value is present.
var compileOnSave *bool
if raw, ok := parsedConfig.raw.(*collections.OrderedMap[string, any]); ok {
if value, ok := raw.GetOrZero("compileOnSave").(bool); ok {
compileOnSave = &value
}
Andrew Branch (andrewbranch)
left a comment
There was a problem hiding this comment.
This is looking very good!
Andrew Branch (andrewbranch)
left a comment
There was a problem hiding this comment.
Nice! Looks like this caught several config parsing bugs along the way. Thank you!
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 18 out of 18 changed files in this pull request and generated 1 comment.
Suppressed comments (1)
internal/tsoptions/tsconfigparsing.go:980
parseJsonConfigFileContentis expected to normalizeraw.compileOnSaveto a boolean even when the property is absent or invalid. The reference implementation always assignsconvertCompileOnSaveOptionFromJson(...), whose default/error result isfalse(_submodules/TypeScript/src/compiler/commandLineParser.ts:3507-3514,3725-3730). This conditional leaves the key absent, or storesnilafter a type error, and also lets an omitted value inherittruefrom an extended JSON config when the reference JSON API does not. Always write the normalized boolean default.
if compileOnSave, ok := json.Get("compileOnSave"); ok {
converted, compileOnSaveErrors := convertJsonOption(compileOnSaveCommandLineOption, compileOnSave, basePath, nil, nil, nil)
errors = append(errors, compileOnSaveErrors...)
json.Set("compileOnSave", converted)
In the TS API, these are exposed as:
parseCommandLine(commandLine: readonly string[], readFile?: (path: string) => string | undefined)readConfigFile(fileName: string, readFile: (path: string) => string | undefined)parseJsonConfigFileContent(json: any, host: ParseConfigHost, basePath: string, existingOptions?: CompilerOptions, configFileName?: string, resolutionStack?: Path[], extraFileExtensions?: readonly FileExtensionInfo[], extendedConfigCache?: Map<string, ExtendedConfigCacheEntry>, existingWatchOptions?: WatchOptions)Part of #4830