-
Notifications
You must be signed in to change notification settings - Fork 7
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
VS Code / TypeScript integration isn't configured correctly for notebook cells #13
Comments
here are some relevant-looking log messages when you create a new cell:
Judging from the way cells are assigned filenames, I think maybe imports of local files can't be found because the relative path isn't correct? Yup, if I give an absolute path it works. Also maybe that's why config files aren't found? There's also these log messages:
which suggests that it's inferring a config file (because it can't find one relative to the path). I wonder if there was some TypeScript support for these notebook pathnames that got broken somehow. |
VS Code understands files starting with |
|
here's a relevant-looking log message from the TypeScript server (I think?!)
what's going on with the path there? |
seems like TypeScript in notebook cells isn't well-supported 😢 see microsoft/vscode#212367 disabling error highlighting in cells. see DonJayamanne/typescript-notebook#79 (comment) microsoft/vscode#186811 microsoft/vscode#188186 about cell paths not working |
see microsoft/vscode#183688 microsoft/vscode#183685 about finding |
ok looks like TypeScript understands (not sure why it is prepending the project root in that case) |
I think dynamic files are supposed to look in the project root for their |
the path in |
missing file error is defined here: https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json#L1887 (I think this gets compiled into a code file which is referenced from called here (in function resolveExternalModuleName(location: Node, moduleReferenceExpression: Expression, ignoreErrors?: boolean): Symbol | undefined {
const isClassic = getEmitModuleResolutionKind(compilerOptions) === ModuleResolutionKind.Classic;
const errorMessage = isClassic ?
Diagnostics.Cannot_find_module_0_Did_you_mean_to_set_the_moduleResolution_option_to_nodenext_or_to_add_aliases_to_the_paths_option
: Diagnostics.Cannot_find_module_0_or_its_corresponding_type_declarations;
return resolveExternalModuleNameWorker(location, moduleReferenceExpression, ignoreErrors ? undefined : errorMessage);
} |
looks like |
resolving import names boils down to https://github.com/microsoft/TypeScript/blob/27bcd4cb5a98bce46c9cdd749752703ead021a4b/src/compiler/program.ts#L2050 which doesn't consider dynamic paths afaict |
I hacked around it by checking for the magic notebook cell pathname, and in that case passing through the underlying notebook pathname: function resolveModuleNamesWorker(moduleNames: readonly StringLiteralLike[], containingFile: SourceFile, reusedNames: readonly StringLiteralLike[] | undefined): readonly ResolvedModuleWithFailedLookupLocations[] {
if (!moduleNames.length) return emptyArray;
const cellPrefix = "^/vscode-notebook-cell/ts-nul-authority";
const containingFileName =
containingFile.originalFileName.startsWith(cellPrefix) ?
containingFile.originalFileName.substring(cellPrefix.length) :
getNormalizedAbsolutePath(containingFile.originalFileName, currentDirectory);
... and now |
looks like TypeScript infers a project (called |
this ☝ is used in an |
when searching for a config file from a file path, dynamic files are skipped https://github.com/microsoft/TypeScript/blob/27bcd4cb5a98bce46c9cdd749752703ead021a4b/src/server/editorServices.ts#L2234 but it seems like no the code above that skips dynamic files is part of microsoft/TypeScript#35111; I think the intent is to have an inferred project. the meaning of "dynamic" files seems overloaded; for notebook cells there is an underlying file so maybe they shouldn't be dynamic. but cells are separate documents, and there needs to be a way for VS Code to find the cell to report errors, which is why the URI is encoded as a dynamic filename. |
I think in |
db7a140 documents using this hacked TypeScript going to close this, I'll see about upstreaming the fixes somehow. |
see also microsoft/vscode#196172 |
filed microsoft/vscode#213740 |
tsconfig.json
Advice from @Krzysztof-Cieslak about debugging:
The text was updated successfully, but these errors were encountered: