sgwilym / nova-deno

A Deno extension for Nova.
https://extensions.panic.com/extensions/co.gwil/co.gwil.deno/
MIT License
13 stars 1 forks source link

Expects a workspace path #20

Closed belcar-s closed 2 years ago

belcar-s commented 2 years ago
Screen Shot 2022-04-21 at 12 07 54 AM

Pressing ⇧⌘N opens windows that aren't associated to any folder, and opening a JavaScript file in one of those windows prompts the extension to crash.

The little arrow shown in the screenshot leads you to the following lines of code. I think join is throwing when workspacePath is nullish.

const workspacePath = nova.workspace.path;
const denoConfigPath = nova.path.join(workspacePath, "deno.json");
const configWatcher = nova.fs.watch(denoConfigPath, () => {
  taskDisposable.dispose();
  taskDisposable.add(registerDenoTasks());
  nova.commands.invoke("co.gwil.deno.commands.restartServer");
});

The solution might simply be to skip those lines if there's no workspace.path :). Unfortunately, there seems to be similar code elsewhere; solving this issue could be a little harder.

sgwilym commented 2 years ago

Oh that's interesting, I'd never considered this case with the new window.

Yeah I'll just skip watching if there's no path. I think once a workspace would become defined the extension would reactivate, so no need to do anything else (?)

belcar-s commented 2 years ago

I think once a workspace would become defined the extension would reactivate, so no need to do anything else (?)

Yup. I tested this with an extension whose activate function just prints the workspace path:

https://user-images.githubusercontent.com/73370025/164490871-42b32e16-2128-48e5-ba95-165fd65e5447.mov

I was worried it would be more complicated because I saw this code in DenoTaskAssistant. I missed the return statement :).

class DenoTaskAssistant implements TaskAssistant {
  provideTasks() {
    const workspacePath = nova.workspace.path;

    if (!workspacePath) {
      return [];
    }

I'm glad it's easy to fix.