Skip to content
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

VSCode's intellisense misses variables from blocks that contain "import" statements #56

Open
dbuezas opened this issue Aug 1, 2021 · 11 comments

Comments

@dbuezas
Copy link

dbuezas commented Aug 1, 2021

Execution obviously works as intended, but error reporting (squiggle lines) and code autocompletion (outside of the block) break as soon as an import statement is used.

image

This doesn't happen if I use const { display } = require("tslab"), but then display is of type any

@dbuezas
Copy link
Author

dbuezas commented Aug 1, 2021

For the time being, here are a couple of workarounds to get both Intellisense and execution working

for node modules that export objects

// import * as tslab from "tslab"; // If I use this line, nothing declared in this block is visible in other blocks
const tslab = require("tslab") as typeof import('tslab')

// import { newPlot } from "./plot"
const { newPlot } = require('./plot') as typeof import('/...full-absolute-path-to-project.../src/plot') // (*)


// use tslab in this or any subsequent block

(*) Intellisense seems to be completely lost about the CWD. I can't get any relative path to work with imports.

I think when classes are exported this method throws an error:
3:7 - Exported variable 'PriorityQueue' has or is using name 'PriorityQueue' from external module "js-priority-queue" but cannot be named.
The following method works

if that doesn't work

block 1:

// @ts-ignore
import PriorityQueue_ from 'js-priority-queue'; // with this line, nothing declare in this block is visible for Intellisense in other blocks

block 2:

// @ts-ignore
const PriorityQueue = PriorityQueue_ as typeof import('js-priority-queue') // Intellisense will complain about PriorityQueue_ not being defined

// use PriorityQueue in this or any subsequent block

@dbuezas
Copy link
Author

dbuezas commented Aug 1, 2021

Here are some clues:

  • using await at the top level gives a kernel runtime error await is only valid in async functions and the top level bodies of modules
  • if there is an import statement in the same block, then the runtime works with awaits in the top level.

Therefore:

  • It looks the block is converted into a module if it makes use of import (you would know, you made this awesome kernel).
  • That could be the reason for vscode's Intellisense to stop "exporting" those variables to other blocks.
  • And also for vscode to lose track of the current working directory when requiring local files!

@dbuezas
Copy link
Author

dbuezas commented Aug 3, 2021

Also reported here: microsoft/vscode#130000

@sahin52
Copy link

sahin52 commented Aug 9, 2021

This issue is not related to Jupyter. When working on a browser (with jupyter-notebook), Jupyter helps me when I type something from the block with an import and pressing on tab; but the imports and variables on import blocks give error on vs code with tslab.

@sahin52
Copy link

sahin52 commented Aug 9, 2021

Btw, the workarounds did not work for me.

@dbuezas
Copy link
Author

dbuezas commented Aug 9, 2021

Btw, the workarounds did not work for me.

Neither? Interesting, I'm using those

@sahin52
Copy link

sahin52 commented Aug 9, 2021

Tried again, now it works, but I couldn't understand why. Thanks for your workaround:
const tslab = require("tslab") as typeof import('tslab')
Sorry and thanks for your time.

@dannysemi
Copy link

This workaround worked perfectly for me. Maybe a wiki page or something to make this easier to find?

@aecorredor
Copy link

@dbuezas I'm also facing this issue, but, on top of that, execution also doesn't work for me inside VSCode. However, it does work when I execute notebooks inside Jupyter Lab. I did install everything locally as explained in the README, and actually see the kernels listed in the terminal. Is there some extra step needed to make VSCode work with the tslab TypeScript kernel?

@dbuezas
Copy link
Author

dbuezas commented Feb 17, 2023

@aecorredor maybe you didn't select tslab as kernel for the notebook in vscode?

@aecorredor
Copy link

I did. That's the weird thing. Here's a more complete error log:

I did. That's the weird thing.

I guess the question is, did it just work out of the box for you once you had the kernel installed?

Here's a more complete error log:

info 11:26:08.301: Starting Jupyter Session startUsingLocalKernelSpec, .tslab./tslab./.tslab#kernel#--config-path#{connection_file} for '/Users/reports/typescript_example.ipynb' (disableUI=false)
info 11:26:08.309: Launching Raw Kernel TypeScript # tslab
info 11:26:08.310: Process Execution: > tslab kernel --config-path ~/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json
> tslab kernel --config-path ~/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json
info 11:26:08.310: Process Execution: cwd: ~/Code/cost-reporting/reports
cwd: ~/Code/cost-reporting/reports
error 11:26:08.311: Kernel died Error: spawn tslab ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn tslab',
  path: 'tslab',
  spawnargs: [
    'kernel',
    '--config-path',
    '/Users/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json'
  ]
} 
error 11:26:08.311: Disposing kernel process due to an error Error: spawn tslab ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn tslab',
  path: 'tslab',
  spawnargs: [
    'kernel',
    '--config-path',
    '/Users/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json'
  ]
}
error 11:26:08.311: 
info 11:26:08.311: Dispose Kernel process undefined.
error 11:26:08.313: Kernel Launcher. launch, Class name = vp, completed in 11ms, has a falsy return value, Arg 1: {"id":".tslab./tslab./.tslab#kernel#--config-path#{connection_file}","kernelSpec":{"specFile":"/Users/Library/Jupyter/kernels/tslab/kernel.json","name":"tslab","argv":["tslab","kernel","--config-path","{connection_file}"],"language":"typescript","executable":"tslab","display_name":"TypeScript","metadata":{"vscode":{"originalSpecFile":"/Users/Library/Jupyter/kernels/tslab/kernel.json","originalDisplayName":"TypeScript"}}},"kind":"startUsingLocalKernelSpec"}, Arg 2: 60000, Arg 3: "~/Code/cost-reporting/reports/typescript_example.ipynb", Arg 4: "~/Code/cost-reporting/reports", Arg 5: <argument cannot be serialized for logging> op [Error]: 
    at new pn (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1628691)
    at new Hi (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1725820)
    at new op (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:100013)
    at hp.launch (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:104888)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Error: spawn tslab ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  category: 'unknown',
  originalException: Error: spawn tslab ENOENT
      at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
      at onErrorNT (node:internal/child_process:478:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn tslab',
    path: 'tslab',
    spawnargs: [
      'kernel',
      '--config-path',
      '/Users/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json'
    ]
  },
  kernelConnectionMetadata: Qd {
    kind: 'startUsingLocalKernelSpec',
    kernelSpec: id {
      specFile: '/Users/Library/Jupyter/kernels/tslab/kernel.json',
      interpreterPath: undefined,
      isRegisteredByVSC: undefined,
      name: 'tslab',
      argv: [Array],
      language: 'typescript',
      executable: 'tslab',
      display_name: 'TypeScript',
      metadata: [Object],
      env: undefined,
      interrupt_mode: undefined
    },
    interpreter: undefined,
    id: '.tslab./tslab./.tslab#kernel#--config-path#{connection_file}'
  },
  stdErr: '\n\n'
}
error 11:26:08.313: Failed to connect raw kernel session: Error: The kernel died. Error: ... View Jupyter [log](command:jupyter.viewOutput) for further details.
warn 11:26:08.314: Error occurred while trying to start the kernel, options.disableUI=false op [Error]: 
    at new pn (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1628691)
    at new Hi (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1725820)
    at new op (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:100013)
    at hp.launch (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:104888)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Error: spawn tslab ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  category: 'unknown',
  originalException: Error: spawn tslab ENOENT
      at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
      at onErrorNT (node:internal/child_process:478:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn tslab',
    path: 'tslab',
    spawnargs: [
      'kernel',
      '--config-path',
      '/Users/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json'
    ]
  },
  kernelConnectionMetadata: Qd {
    kind: 'startUsingLocalKernelSpec',
    kernelSpec: id {
      specFile: '/Users/Library/Jupyter/kernels/tslab/kernel.json',
      interpreterPath: undefined,
      isRegisteredByVSC: undefined,
      name: 'tslab',
      argv: [Array],
      language: 'typescript',
      executable: 'tslab',
      display_name: 'TypeScript',
      metadata: [Object],
      env: undefined,
      interrupt_mode: undefined
    },
    interpreter: undefined,
    id: '.tslab./tslab./.tslab#kernel#--config-path#{connection_file}'
  },
  stdErr: '\n\n'
}
warn 11:26:08.314: Kernel Error, context = start op [Error]: 
    at new pn (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1628691)
    at new Hi (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1725820)
    at new op (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:100013)
    at hp.launch (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:104888)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Error: spawn tslab ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  category: 'unknown',
  originalException: Error: spawn tslab ENOENT
      at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
      at onErrorNT (node:internal/child_process:478:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn tslab',
    path: 'tslab',
    spawnargs: [
      'kernel',
      '--config-path',
      '/Users/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json'
    ]
  },
  kernelConnectionMetadata: Qd {
    kind: 'startUsingLocalKernelSpec',
    kernelSpec: id {
      specFile: '/Users/Library/Jupyter/kernels/tslab/kernel.json',
      interpreterPath: undefined,
      isRegisteredByVSC: undefined,
      name: 'tslab',
      argv: [Array],
      language: 'typescript',
      executable: 'tslab',
      display_name: 'TypeScript',
      metadata: [Object],
      env: undefined,
      interrupt_mode: undefined
    },
    interpreter: undefined,
    id: '.tslab./tslab./.tslab#kernel#--config-path#{connection_file}'
  },
  stdErr: '\n\n'
}
info 11:26:08.317: Dispose Kernel '/Users/reports/typescript_example.ipynb' associated with '/Users/reports/typescript_example.ipynb'
error 11:26:08.319: Error in execution op [Error]: 
    at new pn (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1628691)
    at new Hi (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1725820)
    at new op (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:100013)
    at hp.launch (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:104888)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Error: spawn tslab ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  category: 'unknown',
  originalException: Error: spawn tslab ENOENT
      at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
      at onErrorNT (node:internal/child_process:478:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn tslab',
    path: 'tslab',
    spawnargs: [
      'kernel',
      '--config-path',
      '/Users/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json'
    ]
  },
  kernelConnectionMetadata: Qd {
    kind: 'startUsingLocalKernelSpec',
    kernelSpec: id {
      specFile: '/Users/Library/Jupyter/kernels/tslab/kernel.json',
      interpreterPath: undefined,
      isRegisteredByVSC: undefined,
      name: 'tslab',
      argv: [Array],
      language: 'typescript',
      executable: 'tslab',
      display_name: 'TypeScript',
      metadata: [Object],
      env: undefined,
      interrupt_mode: undefined
    },
    interpreter: undefined,
    id: '.tslab./tslab./.tslab#kernel#--config-path#{connection_file}'
  },
  stdErr: '\n\n'
}
error 11:26:08.320: Error in execution (get message for cell) op [Error]: 
    at new pn (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1628691)
    at new Hi (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1725820)
    at new op (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:100013)
    at hp.launch (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:104888)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Error: spawn tslab ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  category: 'unknown',
  originalException: Error: spawn tslab ENOENT
      at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
      at onErrorNT (node:internal/child_process:478:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn tslab',
    path: 'tslab',
    spawnargs: [
      'kernel',
      '--config-path',
      '/Users/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json'
    ]
  },
  kernelConnectionMetadata: Qd {
    kind: 'startUsingLocalKernelSpec',
    kernelSpec: id {
      specFile: '/Users/Library/Jupyter/kernels/tslab/kernel.json',
      interpreterPath: undefined,
      isRegisteredByVSC: undefined,
      name: 'tslab',
      argv: [Array],
      language: 'typescript',
      executable: 'tslab',
      display_name: 'TypeScript',
      metadata: [Object],
      env: undefined,
      interrupt_mode: undefined
    },
    interpreter: undefined,
    id: '.tslab./tslab./.tslab#kernel#--config-path#{connection_file}'
  },
  stdErr: '\n\n'
}
error 11:26:08.321: Error in execution op [Error]: 
    at new pn (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1628691)
    at new Hi (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1725820)
    at new op (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:100013)
    at hp.launch (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:104888)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Error: spawn tslab ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  category: 'unknown',
  originalException: Error: spawn tslab ENOENT
      at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
      at onErrorNT (node:internal/child_process:478:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn tslab',
    path: 'tslab',
    spawnargs: [
      'kernel',
      '--config-path',
      '/Users/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json'
    ]
  },
  kernelConnectionMetadata: Qd {
    kind: 'startUsingLocalKernelSpec',
    kernelSpec: id {
      specFile: '/Users/Library/Jupyter/kernels/tslab/kernel.json',
      interpreterPath: undefined,
      isRegisteredByVSC: undefined,
      name: 'tslab',
      argv: [Array],
      language: 'typescript',
      executable: 'tslab',
      display_name: 'TypeScript',
      metadata: [Object],
      env: undefined,
      interrupt_mode: undefined
    },
    interpreter: undefined,
    id: '.tslab./tslab./.tslab#kernel#--config-path#{connection_file}'
  },
  stdErr: '\n\n'
}
error 11:26:08.321: Error in execution (get message for cell) op [Error]: 
    at new pn (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1628691)
    at new Hi (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:2:1725820)
    at new op (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:100013)
    at hp.launch (/Users/.vscode/extensions/ms-toolsai.jupyter-2023.1.2010391206/out/extension.node.js:17:104888)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Error: spawn tslab ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:478:16)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  category: 'unknown',
  originalException: Error: spawn tslab ENOENT
      at Process.ChildProcess._handle.onexit (node:internal/child_process:283:19)
      at onErrorNT (node:internal/child_process:478:16)
      at processTicksAndRejections (node:internal/process/task_queues:83:21) {
    errno: -2,
    code: 'ENOENT',
    syscall: 'spawn tslab',
    path: 'tslab',
    spawnargs: [
      'kernel',
      '--config-path',
      '/Users/Library/Jupyter/runtime/kernel-v2-40423sLT6GGXh3aIW.json'
    ]
  },
  kernelConnectionMetadata: Qd {
    kind: 'startUsingLocalKernelSpec',
    kernelSpec: id {
      specFile: '/Users/Library/Jupyter/kernels/tslab/kernel.json',
      interpreterPath: undefined,
      isRegisteredByVSC: undefined,
      name: 'tslab',
      argv: [Array],
      language: 'typescript',
      executable: 'tslab',
      display_name: 'TypeScript',
      metadata: [Object],
      env: undefined,
      interrupt_mode: undefined
    },
    interpreter: undefined,
    id: '.tslab./tslab./.tslab#kernel#--config-path#{connection_file}'
  },
  stdErr: '\n\n'
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants