Giter Club home page Giter Club logo

vim-tsdetect's Introduction

vim-tsdetect

npm Luma Style Guide GitHub Workflow Status - CI Codecov

vim-tsdetect/coc-tsdetect provides vim/neovim and coc.nvim extension to initialize workspace automatically for coc-tsserver and coc-deno.

Installation

Run :CocInstall coc-tsdetect in vim/neovim or install vim-tsdetect with your favorite plugin manager and build with pnpm install && pnpm run build. It is enough to install one of them.

How does this detect TS environments?

Checking following in order.

  1. If buffer name starts with deno:/ -> deno
  2. If buffer name ends with .js, .ts, .tsx -> check following in order
    a. Shebang is present and including node -> node
    b. Shebang is present and including deno -> deno
    c. node_modules/ directory is found in ancestors of (following) -> node
    - If buffer name is not empty, search from that path.
    - Otherwise, search from current working directory.
    d. Otherwise. -> deno
  3. -> Check following in order
    a. Shebang is present and including node -> node
    b. Shebang is present and including deno -> deno
  4. Otherwise, nothing is detected.

When does this try to detect?

This tries to detect when following events occurred.

  • FileType javascript,javascriptreact,typescript,typescript.tsx,typescriptreact
  • BufEnter,BufNewFile,BufWritePost *

Options

Please configure following if necessary by :CocConfig.

tsdetect.mode

Set this "manual" to disable auto initialization. Variable b:tsdetect_is_node remains available.

Values: "auto" | "manual"

Default:

{
  "tsdetect.mode": "auto"
}

tsdetect.doNotCreateOnNode

By default, in Node.js environment, tsdetect does not create a workspace configuration (.vim/coc-settings.json). Set this false to create configuration file whether the configuration exists.

Values: boolean

Default:

{
  "tsdetect.doNotCreateOnNode": true
}

tsdetect.nodeOverride

Workspace configuration to be set in Node.js environment. If you want to extend original configuration, you need to include default ones. Not recommended to touch deno.enable and tsserver.enable.

Values: object

Default:

{
  "tsdetect.nodeOverride": {
    "deno.lint": false,
    "coc.source.file.trimSameExts": [
      ".js",
      ".ts"
    ],
    "prettier.disableLanguages": []
  }
}

tsdetect.denoOverride

Workspace configuration to be set in Deno environment. If you want to extend original configuration, you need to include default ones. Not recommended not to touch deno.enable and tsserver.enable.

Values: object

Default:

{
  "tsdetect.denoOverride": {
    "deno.lint": true,
    "coc.source.file.trimSameExts": [],
    "prettier.disableLanguages": [
      "javascript",
      "javascriptreact",
      "typescript",
      "typescriptreact"
    ]
  }
}

Events

tsdetect#detect

Fired when the tsdetect detects TypeScript environment in the flow shown in above.

tsdetect#detect#node

Fired when tsdetect#detect is fired and environment was detected as node.

tsdetect#detect#deno

Fired when tsdetect#detect is fired and environment was detected as deno.

tsdetect#coc#auto#switch#node#after

Fired after the automatic switch to node triggered and finished.

tsdetect#coc#auto#switch#deno#after

Fired after the automatic switch to deno triggered and finished.

Variables

b:tsdetect_is_node

Set when tsdetect#detect is fired.

Limitations

  • Not recommended to include deno.enable and tsserver.enable settings in user configuration (~/.vim/coc-settings.json that can be opened by :CocConfig).
  • To prevent .vim/ directory being committed by VCS, you can globally ignore .vim/, or ignore one by one using git update-index --skip-worktree .vim for git projects.

Example Configurations

Example for deno.cache on save if deno environment is detected:

function! s:my_coc_tsdetect_buf_write_post() abort
  if !get(g:, 'coc_enabled', 0)
    return
  endif
  if exists('b:tsdetect_is_node') && !b:tsdetect_is_node
    CocCommand deno.cache
  endif
endfunction

augroup my-coc-tsdetect
  autocmd!
  autocmd BufWritePost * call <SID>my_coc_tsdetect_buf_write_post()
augroup END

LICENSE

MIT

Author

Luma

vim-tsdetect's People

Contributors

lumakernel avatar semantic-release-bot avatar tani avatar

Stargazers

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

Watchers

 avatar  avatar  avatar

Forkers

isabella232 tani

vim-tsdetect's Issues

The automated release is failing 🚨

🚨 The automated release from the master branch failed. 🚨

I recommend you give this issue a high priority, so other packages depending on you could benefit from your bug fixes and new features.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. I’m sure you can resolve this πŸ’ͺ.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the master branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here is some links that can help you:

If those don’t help, or if this issue is reporting something you think isn’t right, you can always ask the humans behind semantic-release.


No npm token specified.

An npm token must be created and set in the NPM_TOKEN environment variable on your CI environment.

Please make sure to create an npm token and to set it in the NPM_TOKEN environment variable on your CI environment. The token must allow to publish to the registry https://registry.npmjs.org/.


Good luck with your project ✨

Your semantic-release bot πŸ“¦πŸš€

After installing, I see "No matching autocommands: User tsdetect#detect#node"

Thank you for this project. I hope to get it running properly πŸ˜„

I see the following in my status bar after loading a .ts file in a node project (though it is not an error, only in statusbar, and only shows sometimes):

Screen Shot 2022-08-26 at 4 03 14 PM

Furthermore, I see the following errors before the buffer opens up when I try to load a .ts file from a deno project:

Screen Shot 2022-08-26 at 4 01 24 PM

That said, running :echo b:tsdetect_is_node returns 1 when I'm in a node project, and 0 when I'm in a deno project - so it seems to be working OK somehow.

I am trying to use this project to conditionally deactivate the coc-tsserver extension + activate the coc-deno extension when working in a deno project, and vice-versa when working in a node project.

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.