Code Monkey home page Code Monkey logo

coc-volar's Introduction

coc-volar

fork from a vuejs/language-tools/extensions/vscode

Vue Language Features (Volar) extension for coc.nvim coc-volar-demo

Install

:CocInstall @yaegassy/coc-volar

scoped packages

Note

  • coc-volar version v0.35.0 and later uses vue-language-server version v2.x.x. If you have coc-typescript-vue-plugin installed, please uninstall it as it will cause conflicts and errors.
    • :CocUninstall @yaegassy/coc-typescript-vue-plugin
  • To utilize various language features such as IntelliSense, Diagnostics, and more in the <script> blocks of Vue files, you need to install either coc-tsserver or coc-tsserver-dev.
    • :CocInstall coc-tsserver or :CocInstall coc-tsserver-dev
    • Note: coc-volar checks if coc-tsserver or coc-tsserver-dev are installed in the environment when opening a Vue file. If they are installed, coc-volar automatically starts tsserver.

[RECOMMENDED] Additional installation of "watchman"

In the @vue/language-server used by coc-volar, it utilizes the workspace/didChangeWatchedFiles notification to watch files within the project.

In coc.nvim, it is recommended to install watchman in order to utilize this feature.

If you have difficulty installing watchman, you can use coc-volar without watchman, but you may not be able to immediately use volar's IntelliSense with the newly added files.

In this case, please execute the command to restart the language server.

  • :CocRestart

workspaceFolders

Depending on the project like mono repo or how Vim/Neovim is started, workspaceFolders may not be recognized correctly.

If workspaceFolders are not recognized correctly, the language server may parse unnecessary project folders, etc., slowing down the operation. Or Language Server may not work properly.

The default configuration of coc.nvim resolves to the directory where the .git, .hg, or .projections.json files reside as the workspace root.

coc-volar has also already added vite.config.ts, vite.config.js, vue.config.js or nuxt.config.ts to the extension side to resolve workspace root.

If further customization is needed, set b:coc_root_patterns in ".vimrc/init.vim".

Example:

  au FileType vue let b:coc_root_patterns = ['.git', '.env', 'package.json', 'tsconfig.json', 'jsconfig.json', 'vite.config.ts', 'vite.config.js', 'vue.config.js', 'nuxt.config.ts']

For more information, check this coc.nvim's wiki.

iskeyword

If the completion menu disappears when typing -, add the iskeyword setting to .vimrc / init.vim.

autocmd Filetype vue setlocal iskeyword+=-

Configuration options

  • volar.enable: Enable coc-volar extension, default: true
  • volar.useWorkspaceTsdk: Use workspace (project) detected tsLibs in volar. if false, use coc-volar's built-in tsLibs, default: false
  • volar.tsLocale: Sets the locale used to report diagnostics message from typescript, valid option: ["cs", "de", "es", "fr", "it", "ja", "ko", "en", "pl", "pt-br", "ru", "tr", "zh-cn", "zh-tw"], default: "en"
  • volar.autoCreateQuotes: Enable/disable auto creation of quotes for HTML attribute assignment, default: false
  • volar.autoClosingTags: Enable/disable autoClosing of HTML tags, default: false
  • volar.scaffoldSnippets.enable: Enable/disable scaffold snippets completion. Typing vue or vuedc will output completion suggestions. This snippets completion feature will only work on the first line of the file, default: true
  • volar.disableCompletion: Disable completion from Volar, default: false
  • volar.disableDiagnostics: Disable diagnostics from Volar, default: false
  • volar.disableFormatting: Disable formatting from Volar, default: false
  • volar.disableProgressNotifications: Disable the initialization and workdone progress notifications, default: false
  • vue.trace.server: Traces the communication between coc.nvim and the language server, valid option: ["off", "messages", "verbose"], default: "off"
  • vue.server.path: Custom path to volar server module, ~ and $HOME can also be used. If there is no setting, the built-in module will be used, default: null
  • vue.server.maxFileSize: Maximum file size for Vue Language Server to load. (default: 20MB), default: 20971520
  • vue.server.maxOldSpaceSize: Set --max-old-space-size option on server process. If you have problem on frequently "Request textDocument/** failed." error, try setting higher memory(MB) on it, default: null
  • vue.codeActions.enabled: Enabled code actions, default: true
  • vue.codeLens.enabled: Enabled code lens, default: true
  • vue.complete.casing.tags: Preferred tag name case, valid options: ["autoKebab", "autoPascal", "kebab", "pascal"], default: "autoPascal"
  • vue.complete.casing.props: Preferred attr name case, valid options: ["autoKebab", "autoCamel", "kebab", "camel"], default: "autoKebab"
  • vue.autoInsert.parentheses: Auto-wrap () to As Expression in interpolations for fix volar-issue #520, default: true
  • vue.autoInsert.dotValue: Auto-complete Ref value with .value, default: false
  • vue.autoInsert.bracketSpacing: Auto add space between double curly brackets: {{|}} -> {{ | }}, default: true
  • vue.inlayHints.missingProps: Show inlay hints for missing required props, false
  • vue.inlayHints.inlineHandlerLeading: Show inlay hints for event argument in inline handlers, default: false
  • vue.inlayHints.optionsWrapper: Show inlay hints for component options wrapper for type support, default: false

Commands

  • vue.action.restartServer: Restart Vue server

More features

Other major LSP feature are of course supported as well.

completion, definition, typeDefinition, diagnostics, hover, signatureHelp, references, codeLens, formatting, rename and more...

Thanks

License

MIT


This extension is built with create-coc-extension

coc-volar's People

Contributors

johnsoncodehk avatar yaegassy avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

coc-volar's Issues

Autoimport only works for "script setup" components

Hi,

The component auto import feature only works if the imported component is defined by "script setup",

Here is an print when i try to import a non script setup component into one.

Screenshot from 2021-08-25 12-13-12

Is there any configuration that i'm missing?

Thanks in advance

Auto release new version with `@volar/server`

When volar updated, coc-volar usually does not need to change the code. Are you interested in using GitHub Action to automatically release coc-volar when @volar/server released a new version? (If tsc compile pass)

Auto import has a bug

When I auto import some function from vue, for example the onMounted function, this plugin cause some problem.

image.png

It prompts that [coc.nvim]Error on applyEdits:file:///[My file address changed] before apply edit

Not recognizing vue files created after server startup

Description

This is a problem only with coc-volar. VSCode's volar extension is not a problem.

I think it will be reflected since there is a createFileSystemWatcher to begin with, but I don't know the cause.

REF

  const clientOptions: LanguageClientOptions = {
    // ...snip
    synchronize: {
      fileEvents: workspace.createFileSystemWatcher('{**/*.vue,**/*.js,**/*.jsx,**/*.ts,**/*.tsx,**/*.json}'),
    },
    // ...snip

DEMO

coc-volar-bug.mp4

Misc

Unfortunately, this symptom seems to be a problem only with coc-volar. Other Vim plugins that use volar do not seem to have this problem.

It seems to be the same with vim-lsp and Neovim builtin lsp.

"CursorHold" error related to Code Lens when launching the extension.

There seems to be an error in the background at startup when the Code Lens feature is enabled ("codeLens.enable": true in coc-settings.json).

There is nothing wrong with the operation of the extension itself, but it needs to be modified so that the error does not occur.

(As an additional note, this error seems to have occurred since the early development of coc-volar)

Log of coc.nvim:

Repro: :CocInfo

2021-08-02T08:50:27.543 WARN (pid:18787) [events] - Handler of CursorHold blocked more than 2s: Error
    at Events.on (/Users/yaegassy/.local/share/nvim/plugged/coc.nvim/build/index.js:18356:23)
    at CodeLensManager2.listen (/Users/yaegassy/.local/share/nvim/plugged/coc.nvim/build/index.js:66679:24)
    at new CodeLensManager2 (/Users/yaegassy/.local/share/nvim/plugged/coc.nvim/build/index.js:66671:14)
    at new Handler (/Users/yaegassy/.local/share/nvim/plugged/coc.nvim/build/index.js:70517:25)
    at Plugin.init (/Users/yaegassy/.local/share/nvim/plugged/coc.nvim/build/index.js:70924:26)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at async /Users/yaegassy/.local/share/nvim/plugged/coc.nvim/build/index.js:71122:11

Capture:

coc-volar-issue-startup-backgroud-error

Some CodeActions cannot be executed due to errors

CodeAction works fine when the file is opened for the first time, but an error occurs when the file is modified.

CodeAction where the problem occurs.

  • Delete all unused imports
  • Organize Imports

The following code actions seem to work fine

  • Remove unused declaration for: '...'

DEMO (mp4):

coc-volar-codeaction-error-issue.mp4

Similar past issues

Disable autocompletion source

Is there a way to disable autocompletion suggestions from the Volar LS? I'm getting lots of noise from this plugin/vue-semantic-server via the autocomplete menu - is there a way to disable this programmatically? My current workaround is to call :CocList sources and toggle it off, but it resets each time Vim is opened.

image

The tsserver CoC plugin has configurations like

typescript.suggest.enabled
javascript.suggest.enabled

but I'm not seeing anything similar for Volar in the docs.

Typescript errors in non typescript vue file

Thanks for this project - it works in great for typescript project. I have a non typescript .vue file and now that I upgraded to coc-volar 0.5.10 I started getting typescript errors such as

[ts 2322] [E] Type '() => void' is not assignable to type 'never'.

mostly in callback props. How can I resolve this? Thanks.

works with watchman, renameFile not works.

First of all, A very huge thank you. and then during use, I found that the renaming function does not work properly, and the other related dependent files cannot be modified correctly.

Screen.Recording.2024-03-20.at.17.18.46.mov

Add Configuration for Packer

Hey, it would be really great if you could, add configuration on how to install this using Packer.
I tried it and was just playing around with it.

cd ~/.config/nvim/lua
open packer_init.lua
add
->  use {'neoclide/coc.nvim', branch = 'release'}

":PackerInstall"

Once you have coc.nvim
:CocInstall @yaegassy/coc-volar

Awesome work!
Thanks

in takeover mode using code action auto import only works once

When using volar in takeover mode (by following the instructions laid out in this projects readme), when i use the code action auto module import, it works only once before i have to restart the server.

I am met with this erro message

[coc.nvim] Error on applyEdits: {path to file} changed before apply edit.

after restarting the server on a .vue file, i am able to use the auto import from within a typescript only once yet again

for context this is a vue2 project, and i followed the instructions on the volar project readme for setting things up vue 2 support

show warning for syntax errors?

Normally when I save in vim, it will reformat my vue file. If there is a syntax error, volar will refuse to reformat my vue file silently.

is it possible for volar to provide hints for those wrong syntax or typos in the code? I just spent an hour to check my code and found there is a place I put `;' instead of ',' inside export default.

in c/c++ etc vim scenario, vim can highlight the syntax errors for quick fixes. I wonder if volar can do that too? or it is already there but I just don't know how to set it up?

Add enable/disable setting for volar formatting feature (when using prettier).

Description

coc-volar also needs to support use cases such as disabling the formatting capabilities of volar and using "prettier".

Unfortunately, coc.nvim does not allow you to set editor.defaultFormatter for each filetype, which is configurable in "VSCode".

[Not support] coc.nvim:

"[vue]": {
    "editor.defaultFormatter": "EXTENSION_NAME"
}

About adding feature

Recently, initializationOption was made very flexible in "volar". (Thanks! johnsoncodehk)

Prepare to add the volar.formatting.enable setting so that you can control whether the format is enabled or disabled. (Like vetur's vetur.format.enable)

Misc (Using vue files in coc-prettier)

coc.nvim has an extension for coc-prettier.

The vue file is "disabled" in the default configuration of coc-prettier.

Please change the setting of prettier.disableLanguages

e.g:

Overwrite disableLanguages with empty

{
  // ...snip
  "prettier.disableLanguages": []
  // ...snip
}

the diagnostic can't be used

Since version 0.27.2, the diagnostic function cannot be used, and there is no prompt even if there is a syntax error, which is normal before

How to Enable Local Formatting Configuration?

In my CoC config file, the coc.preferences.formatOnSaveFiletypes list contains vue.

  • With volar.formatting.enable set to true, the file is formatted on save, but the formatter ignores the local configuration for Prettier
  • With volar.formatting.enable set to false, the file is not formatted on save

I recall that coc-vetur had the vetur.useWorkspaceDependencies flag that respected local configurations. Is there something similar for coc-volar? Is there another CoC configuration option that should be used instead?

I've noticed Volar has instructions for VS Code in this instance, but I don't know of an analog for Neovim.

Language Client is not ready yet

Hi, i'm having some trouble to get coc-volar running after the update 0.5.30

It just occur when i type anything inside any vue file.

Screenshot from 2021-09-15 16-09-16

Is there any config im missing?

Add typescript, javascript and related to jsx to "activationEvents"

Description

In the shim (env.d.ts) of create-vue, declare module "*.vue" ... has been intentionally removed.

For editors other than VSCode, the direction seems to be to recommend the use of "Take Over Mode".

In coc-volar, the current flow is to first open the vue file and then run the command to enable Take Over Mode.

  • :CocCommand volar.initializeTakeOverMode

Even if your project already has Take Over Mode enabled, you will need to open the vue file first.

Change

It would be better to be able to enable Take Over Mode more smoothly than currently.

I will soon make changes to activate coc-volar extensions for ts, js, tsx, and jsx files. (VSCode's volar extension like)

  "activationEvents": [
    "onLanguage:vue",
    "onLanguage:javascript",
    "onLanguage:typescript",
    "onLanguage:javascriptreact",
    "onLanguage:typescriptreact",
    "onCommand:volar.initializeTakeOverMode"
  ],

no autocomplete for js or ts code in vue3 file

in the script section of my vue code, it seems there is no autocompete for any javascript or typescript code, is this supposed to work?

tried volar in vscode all autocomplete with javascript and typescript worked fine.

Inserted text by "css completion" may be corrupted

Description

This problem occurs only with coc-volar (coc.nvim). VSCode's volar extension is not a problem.

I have a feeling that the inserted text is broken in the case of fuzzy matching.

e.g:

  • Input: martop -> can be matched margin-top

Demo

Case1

coc-volar-css-completion-issue-1.mp4

Case2

coc-volar-css-completion-issue-2.mp4

Property 'loading' does not exist on type '{}'.

Hi, thanks for plugin.
I am using vue3 composition api
I tested 2 methods, Takeover Mode, and typescript-vue-plugin, but for both have this error.

For example, for this component, i have error from header:

    <div class="container" style="padding: 3.2rem 0;" v-if="loading">
      <LoadingComponent/>
    </div>

And also this error exists and for other Components properties or emits.

I founded in google a lot of reasons, but no one don't work.
Like, to create a file ** vue-file-import.d.ts** with this ext

declare module "*.vue" {
  import Vue from "vue";
  export default Vue;
}

Or in main.ts to add

    app.config.globalProperties.appName = 'vue3'

Thanks in advance.

Cannot jump to component without `.vue` file extension

Hi. I might just be missing some configs, but I cannot jump to a different component when the path of that component does not include the .vue file extension. Jumping to .js files work fine even if they're missing the extension, but for some reason, Vue components need to have a .vue in the import statement for the JumpDefinition to work. Any ideas or workarounds?

Does not work with ts files

It works fine in vue files but in ts files I can't import Vue files.
For example, in src/main.ts :
Screenshot from 2022-08-29 19-45-58

In Vue doc, it is mentioned that we should install TypeScript Vue Plugin.

I'm not sure if coc-colar also installs TypeScript Vue Plugin or if there is another coc implementation to install it.

For me don't work?

Hi, thanks for plugin, but i don't understand how to make them works.
Make

:CocInstall @yaegassy/coc-volar

Also for coc-tsserver

image

But in vue file, i write a component, and don't see errors that need to import.
Also coc-codeaction-cursor don't import.

[0.24.0] Volar not detecting template in script setup

Recently, I upgraded from 0.23.3 to 0.24.
Suddenly, variables and imported components declared in <script setup> show the warning "[ts 6133] value is never read" for using in <template>.

Variables are using in <script setup> are correctly detecting.
However, variables which only used in <template> show "value is never read" warnings.

I rollbacked coc-volar to 0.23.3, There is no problem, and problem has been solved

Remove VSCode dependency

Thanks to create this coc extension!

This extension seem dependency VSCode, maybe helpful if I remove appRoot option and publish @volar/vscode-server?

why watchman as a dependency?

really heavy application, takes a long time to install on linux(along with boost c++ libraries etc), can we use some better alternatives

How to install using self managed registry.

During installation, an Error occured:

- ✗ @yaegassy/coc-volar-tools Request failed using proxy proxy.<companydomain>.com: self-signed certificate in certificate chain
     Using npm from: /home/wangx/node/bin/npm
Get info from https://registry.npmjs.org/ 
Request failed using proxy proxy.<companydomain>.com: self-signed certificate in certificate chain                                                                                                                                                                                                        

It seems that during installation, the plugin will not read the ~/.npmrc or ./.npmrc config file.

Diagnostic issue (not showing)

Diagnostic info is not showing up, probably after I did an update? I don't remember exactly.
I see a similar issue earlier.

Not showing in vue file:
image

Shows in normal ts file:
image

I use takeover mode:

  "volar.takeOverMode.enabled": true,
  "tsserver.enable": false

Diagnostic will show if I change tsserver.enable to true, but I don't think that's what I should do.

Thanks in advance!

Language server crash

After installing as written in the docs and opening any vue file, I get the following error.

[coc.nvim]: UnhandledRejection: Connection to server got closed. Server will not be restarted.
Error: Connection to server got closed. Server will not be restarted.                                                                                                                  
    at np.handleConnectionClosed (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:223:967)
    at np.handleConnectionClosed (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:223:28612)
    at t (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:223:386)
    at tM.invoke (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:9670)
    at sd.fire (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:10436)
    at bi (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:36:10897)
    at tM.invoke (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:9670)
    at sd.fire (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:10436)
    at _M.fireClose (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:12716)
    at ChildProcess.<anonymous> (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:62:11975)
UnhandledRejection: Connection to server got closed. Server will not be restarted.
Error: Connection to server got closed. Server will not be restarted.
    at np.handleConnectionClosed (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:223:967)
    at np.handleConnectionClosed (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:223:28612)
    at t (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:223:386)
    at tM.invoke (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:9670)
    at sd.fire (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:10436)
    at bi (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:36:10897)
    at tM.invoke (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:9670)
    at sd.fire (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:10436)
    at _M.fireClose (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:12716)
    at ChildProcess.<anonymous> (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:62:11975)
UnhandledRejection: Connection to server got closed. Server will not be restarted.
Error: Connection to server got closed. Server will not be restarted.
    at np.handleConnectionClosed (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:223:967)
    at np.handleConnectionClosed (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:223:28612)
    at t (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:223:386)
    at tM.invoke (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:9670)
    at sd.fire (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:10436)
    at bi (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:36:10897)
    at tM.invoke (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:9670)
    at sd.fire (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:10436)
    at _M.fireClose (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:35:12716)
    at ChildProcess.<anonymous> (/home/user/.config/nvim/plugged/coc.nvim/build/index.js:62:11975)
UnhandledRejection: Connection to server got closed. Server will not be restarted.

{
  "name": "Volar doctor info",
  "filePath": "xxx.vue",
  "clientVersion": "0.7.8",
  "serverVersion": "0.29.8",
  "vueVersion": "3.2.22",
  "vueRuntimeDomVersion": "3.2.22",
  "vueTscVersion": "0.29.8",
  "tsVersion": "4.4.3",
  "tsServerPath": "/home/user/.config/coc/extensions/node_modules/@yaegassy/coc-volar/node_modules/typescript/lib/tsserverlibrary.js",
  "settings": {
    "enable": true,
    "useWorkspaceTsdk": false,
    "diagnostics": {
      "enable": true,
      "tsLocale": "en"
    },
    "lowPowerMode": false,
    "codeLens": {
      "references": true,
      "pugTools": false,
      "scriptSetupTools": false
    },
    "autoClosingTags": false,
    "autoCompleteRefs": false,
    "takeOverMode": {
      "enabled": false
    },
    "formatting": {
      "enable": true,
      "printWidth": 100
    },
    "completion": {
      "tagNameCase": "both",
      "attrNameCase": "kebab",
      "autoImportComponent": true
    },
    "dev": {
      "serverPath": ""
    },
    "fix": {
      "completion": true
    }
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.