Skip to content

Commit

Permalink
Potential fix for config options crash (microsoft#6889)
Browse files Browse the repository at this point in the history
* Potential fix for config options crash

* Fix problem with json stringifying a map
  • Loading branch information
rchiodo authored Jan 3, 2024
1 parent bd13735 commit 38b51fa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/pyright-internal/src/backgroundAnalysisBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
InitializationData,
LogData,
createConfigOptionsFrom,
createJsonObjectFrom,
getBackgroundWaiter,
run,
} from './backgroundThreadBase';
Expand Down Expand Up @@ -55,7 +56,8 @@ export class BackgroundAnalysisBase {
}

setConfigOptions(configOptions: ConfigOptions) {
this.enqueueRequest({ requestType: 'setConfigOptions', data: configOptions });
const passable = createJsonObjectFrom(configOptions);
this.enqueueRequest({ requestType: 'setConfigOptions', data: passable });
}

setTrackedFiles(fileUris: Uri[]) {
Expand Down Expand Up @@ -219,7 +221,7 @@ export class BackgroundAnalysisBase {
}

default:
debug.fail(`${msg.requestType} is not expected`);
debug.fail(`${msg.requestType} is not expected. Message structure: ${JSON.stringify(msg)}`);
}
}

Expand Down Expand Up @@ -453,7 +455,7 @@ export abstract class BackgroundAnalysisRunnerBase extends BackgroundThreadBase
}

default: {
debug.fail(`${msg.requestType} is not expected`);
debug.fail(`${msg.requestType} is not expected. Message structure: ${JSON.stringify(msg)}`);
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions packages/pyright-internal/src/backgroundThreadBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,13 @@ export class BackgroundThreadBase {
}
}

export function createJsonObjectFrom(configOptions: ConfigOptions): any {
return {
...JSON.parse(JSON.stringify(configOptions)),
defineConstant: configOptions.defineConstant, // This is the only field that can't be stringified.
};
}

export function createConfigOptionsFrom(jsonObject: any): ConfigOptions {
const configOptions = new ConfigOptions(Uri.fromJsonObj(jsonObject.projectRoot));
const getFileSpec = (fileSpec: any): FileSpec => {
Expand Down

0 comments on commit 38b51fa

Please sign in to comment.