fannheyward / coc-deno

Deno extension for coc.nvim
MIT License
151 stars 9 forks source link

Is there a way to swap tsserver and deno lsp per project? #191

Closed npearson72 closed 1 year ago

npearson72 commented 1 year ago

Perhaps a flag in the root directory?

fannheyward commented 1 year ago

Yes, after you did deno.initializeWorkspace command, coc-deno will enable deno and disable tsserver, and save the settings to .vim/coc-settings.json in your project.

{
  "deno.enable": true,
  "tsserver.enable": false
}

You can change the settings to swap the two LS.

npearson72 commented 1 year ago

Thanks @fannheyward, but I wasn't able to get that command working. I get the following error:

[coc.nvim]: Unable to locate workspace folder configuration for file:///Users/nathan/Dev/learning/deno
Unable to locate workspace folder configuration for file:///Users/nathan/Dev/learning/deno
Unable to locate workspace folder configuration for file:///Users/nathan/Dev/learning/deno
Unable to locate workspace folder configuration for file:///Users/nathan/Dev/learning/deno

Any ideas?

fannheyward commented 1 year ago

What's your :CocInfo? Looks like your coc.nvim is outdated, upgrade your coc.nvim and try again.

npearson72 commented 1 year ago

Seems updated, but am seeing an error when I run CocInfo. I also use adsf to manage deno (not sure if that matters)?

## versions

vim version: NVIM v0.8.0
node version: v16.17.1
coc.nvim version: 0.0.82-75f2b7eb 2022-12-06 00:50:36 +0800
coc.nvim directory: /Users/nathan/.config/nvim/plugged/coc.nvim
term: tmux
platform: darwin

## Log of coc.nvim

2022-12-10T19:28:17.114 INFO (pid:30373) [extension:coc-git] - Looking for git in: git
2022-12-10T19:28:17.273 INFO (pid:30373) [plugin] - coc.nvim initialized with node: v16.17.1 after 316
2022-12-10T19:28:19.137 INFO (pid:30373) [attach] - receive notification: runCommand [ 'deno.initializeWorkspace' ]
2022-12-10T19:28:19.160 INFO (pid:30373) [language-client-index] - Language server "deno" started with 30512
2022-12-10T19:28:20.853 ERROR (pid:30373) [configurations] - Unable to locate workspace folder configuration file:///Users/nathan/Dev/learning/deno Error
    at Object.update (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:152:6784)
    at doInitialize (/Users/nathan/.config/coc/extensions/node_modules/coc-deno/lib/index.js:2448:10)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /Users/nathan/.config/coc/extensions/node_modules/coc-deno/lib/index.js:2459:5
    at async xk.fireCommand (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:69:4089)
    at async bm.runCommand (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:261:24114)
    at async Ym.cocAction (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:281:47116)
    at async RD.<anonymous> (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:281:48848)
2022-12-10T19:28:20.853 ERROR (pid:30373) [configurations] - Unable to locate workspace folder configuration file:///Users/nathan/Dev/learning/deno Error
    at Object.update (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:152:6784)
    at doInitialize (/Users/nathan/.config/coc/extensions/node_modules/coc-deno/lib/index.js:2449:10)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /Users/nathan/.config/coc/extensions/node_modules/coc-deno/lib/index.js:2459:5
    at async xk.fireCommand (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:69:4089)
    at async bm.runCommand (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:261:24114)
    at async Ym.cocAction (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:281:47116)
    at async RD.<anonymous> (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:281:48848)
2022-12-10T19:28:20.854 ERROR (pid:30373) [configurations] - Unable to locate workspace folder configuration file:///Users/nathan/Dev/learning/deno Error
    at Object.update (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:152:6784)
    at doInitialize (/Users/nathan/.config/coc/extensions/node_modules/coc-deno/lib/index.js:2450:10)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /Users/nathan/.config/coc/extensions/node_modules/coc-deno/lib/index.js:2459:5
    at async xk.fireCommand (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:69:4089)
    at async bm.runCommand (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:261:24114)
    at async Ym.cocAction (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:281:47116)
    at async RD.<anonymous> (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:281:48848)
2022-12-10T19:28:20.854 ERROR (pid:30373) [configurations] - Unable to locate workspace folder configuration file:///Users/nathan/Dev/learning/deno Error
    at Object.update (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:152:6784)
    at doInitialize (/Users/nathan/.config/coc/extensions/node_modules/coc-deno/lib/index.js:2453:20)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async /Users/nathan/.config/coc/extensions/node_modules/coc-deno/lib/index.js:2459:5
    at async xk.fireCommand (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:69:4089)
    at async bm.runCommand (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:261:24114)
    at async Ym.cocAction (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:281:47116)
    at async RD.<anonymous> (/Users/nathan/.config/nvim/plugged/coc.nvim/build/index.js:281:48848)
2022-12-10T19:28:20.856 INFO (pid:30373) [attach] - receive notification: runCommand [
  'coc-helper.internal.didVimEvent_m1_v0_15_2_coc_helper_1',
  'BufWipeout',
  2
]
2022-12-10T19:28:20.857 INFO (pid:30373) [attach] - receive notification: runCommand [
  'coc-helper.internal.didVimEvent_m1_v0_15_2_explorer_2',
  'BufWipeout',
  2
]
2022-12-10T19:28:24.428 INFO (pid:30373) [attach] - receive notification: showInfo []
Screen Shot 2022-12-10 at 7 29 09 PM
fannheyward commented 1 year ago

Will check this ASAP.

fannheyward commented 1 year ago

Do you have something like .git in your /Users/nathan/Dev/learning/deno, seems like coc.nvim can't resolve the root of the project.

npearson72 commented 1 year ago

I just tried with and without .git in the root, and same thing:

I also have these settings in coc config:

  "coc.preferences.rootPatterns": [
    "package.json",
    ".gitignore",
    ".env",
    ".git"
  ],

But I tried just now with and without them. Didn't help.

Here is my entire coc config if this helps?

{
  "coc.preferences.formatOnSaveFiletypes": [
    "css",
    "html",
    "go",
    "javascript",
    "javascriptreact",
    "json",
    "jsonc",
    "markdown",
    "prisma",
    "ruby",
    "rust",
    "scss",
    "typescript",
    "typescriptreact",
    "yaml"
  ],
  "coc.preferences.jumpCommand": "tabe",
  "coc.preferences.rootPatterns": [
    "package.json",
    ".gitignore",
    ".env",
    ".git"
  ],
  "coc.preferences.willSaveHandlerTimeout": 5000,
  "coc.source.emoji.filetypes": null,
  "diagnostic.errorSign": "",
  "diagnostic.warningSign": "",
  "diagnostic.infoSign": "",
  "diagnostic.hintSign": "",
  "emmet.includeLanguages": {
    "javascript": "javascriptreact",
    "eruby": "html"
  },
  "emmet.showSuggestionsAsSnippets": true,
  "eslint.run": "onType",
  "explorer.file.reveal.auto": false,
  "explorer.file.child.template": "[git | 2][selection | clip | 1][indent][icon | 1] [diagnosticError & 1][filename omitCenter 1] [readonly & 1][linkIcon & 1][link]",
  "explorer.file.root.template": "[icon] [fullpath]",
  "explorer.file.showHiddenFiles": true,
  "explorer.filename.colored.enable": {
    "diagnosticError": true,
    "diagnosticWarning": false,
    "git": false
  },
  "explorer.git.showIgnored": false,
  "explorer.icon.enableNerdfont": true,
  "explorer.keyMappings.global": {
    "<2-LeftMouse>": "null",
    "<Leader>e": "reveal:select",
    "l": "null",
    "E": "null",
    "v": "open:vsplit"
  },
  "explorer.openAction.relativePath": true,
  "explorer.openAction.strategy": "sourceWindow",
  "explorer.previewAction.onHover": false,
  "explorer.quitOnOpen": true,
  "explorer.sources": [
    {
      "name": "file",
      "expand": true
    }
  ],
  "git.addedSign.hlGroup": "CocGitAdd",
  "git.changedSign.hlGroup": "CocGitChange",
  "git.removedSign.hlGroup": "CocGitDelete",
  "git.topRemovedSign.hlGroup": "CocGitDelete",
  "git.changeRemovedSign.hlGroup": "CocGitDeleteChange",
  "git.changedSign.text": "!",
  "javascript.suggestionActions.enabled": false,
  "javascript.updateImportsOnFileMove.enable": false,
  "prettier.arrowParens": "avoid",
  "prettier.endOfLine": "auto",
  "prettier.printWidth": 80,
  "prettier.singleQuote": true,
  "prettier.trailingComma": "none",
  "snippets.extends": {
    "typescriptreact": ["javascript"],
    "typescript": ["javascript"]
  },
  "solargraph.diagnostics": true,
  "solargraph.formatting": true,
  "suggest.snippetIndicator": " ",
  "suggest.maxCompleteItemCount": 500,
  "suggest.noselect": true,
  "typescript.updateImportsOnFileMove.enable": false,
  "vetur.validation.template": false
}
fannheyward commented 1 year ago

The error is came from coc.nvim that can't resolve and find configuration folder. Try mkdir .vim in your project.

I can't reproduce this error.

https://github.com/neoclide/coc.nvim/blob/9386771d41ad151d7e49fa4c2357f20c8fe1c14d/src/configuration/index.ts#L322-L323

npearson72 commented 1 year ago

Hmm, so I added the following to my main ~/.config/nvim/coc-settings.json file:

  "deno.enable": true,
  "tsserver.enable": false

Then in a local deno project directory, I opened up nvim and ran: CocCommand deno.initializeWorkspace. That produced a <local-deno-project-directory>/.vim/~coc-settings.json file. In it are these values:

{
  "deno.enable": true,
  "deno.lint": true,
  "deno.unstable": true,
  "prettier.disableLanguages": [
    "typescript",
    "javascript"
  ],
  "tsserver.enable": false
}

So it seems I need those settings in my main coc settings file for CocCommand deno.initializeWorkspace to work. 🤔

I then disabled deno in my main coc settings, and enabled tsserver, like so:

  "deno.enable": false,
  "tsserver.enable": true

I did this as I work mostly with node.

Now coming back to my local deno project directory, when I open a ts file, I'm still gettingtsserver instead of deno:

Screen Shot 2022-12-10 at 10 52 13 PM

Is there some flag I need in my main coc settings to allow a local override?

npearson72 commented 1 year ago

Hi @fannheyward, I just wanted to update you. I think my issue was that I was symlinking my main coc-settings.json file from my ~/.dots directory.

After setting g:coc_config_home everything began working normally.

Thank you for looking into this. I'm closing the issue now.