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

script attributes like context="module" or lang="ts" break indent #19

Open
non25 opened this issue Feb 21, 2021 · 5 comments
Open

script attributes like context="module" or lang="ts" break indent #19

non25 opened this issue Feb 21, 2021 · 5 comments

Comments

@non25
Copy link
Contributor

non25 commented Feb 21, 2021

To reprocude, simply add some attributes to the script tag:

<script lang="ts">
  // Pressing S will place cursor here:
  let obj = {
|  
  }
</script>
<script lang="ts">
  let obj = {<CR>};

  // will place cursor like this:
  let obj = {
  |
  };
</script>

Can't seem to figure out what causes this behavior. I've read indent script and haven't found anything that could mess with it.
Perhaps that's another indent/html.vim feature for me.

@non25
Copy link
Contributor Author

non25 commented Feb 21, 2021

Yeah...
That's it:
https://github.com/vim/vim/blob/dc167465f87a4f03f9e085597dfcfdde39fcd2b9/runtime/indent/html.vim#L398-L406

Adding this does the job:

  elseif a:str == "ts" || a:str = "typescript"
    return "typescript"

Can we somehow override functions from indent/html.vim in svelte.vim?

Interesting, after this addition, no matter what modifications I do to the <script> tag, indent works correctly.

@cloudhead
Copy link

I have the same issue.

@evanleck
Copy link
Owner

@cloudhead @non25 sorry for the tremendous delay... I've been trying to improve the HTML indent behavior and found that adding othree/html5.vim fixes some issues. Mind giving that a shot and letting me know how it works? I've updated the README to include html5.vim as a dependency of this plugin as well.

@acarl005
Copy link

@evanleck Giving a little update here. After adding othree/html5.vim, the indent behavior in a <script context="module"> tag still isn't quite right. If I have the following content in a svelte file...

<script context="module">
  function add(a, b) {▌
  }
</script>

...and I press o I get....

<script context="module">
  function add(a, b) {

  }
</script>

The new line is indented to 2 spaces when it should be 4 inside the function body.
I am using the latest NeoVim

nvim --version
NVIM v0.7.2
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew@Monterey

Features: +acl +iconv +tui
See ":help feature-compile"

   system vimrc file: "$VIM/sysinit.vim"
  fall-back for $VIM: "/usr/local/Cellar/neovim/0.7.2/share/nvim"

And here is my ~/.config/nvim/init.lua. I have junegunn/vim-plug installed as my plugin manager

vim.fn["plug#begin"](vim.fn.stdpath("data") .. "/plugged")

vim.fn["plug#"]("othree/html5.vim") -- depended upon by evanleck/vim-svelte
vim.fn["plug#"]("pangloss/vim-javascript") -- depended upon by evanleck/vim-svelte
vim.fn["plug#"]("evanleck/vim-svelte") -- needed for good svelte file indentation

vim.fn["plug#end"]()

vim.o.number = true -- line numbers

vim.o.expandtab = true -- convert tabs to spaces
vim.o.softtabstop = 2 -- how many spaces to insert for each <tab>
vim.o.tabstop = 2 -- the width to display a <tab> character
vim.o.shiftwidth = 2 -- used by commands like =, >, and < to know how much to indent
vim.o.cindent = true

@binarious
Copy link

binarious commented Jan 3, 2023

Same issue here, but I still don't get any indentation even with othree/html5.vim.

Svelte file:

<script lang="ts">
  function test(): void {
  alert('wrong indentation');
  }
</script>

It works without lang="ts". Also doesn't work with lang="typescript".

My init.lua:

require('lazy').setup({
  -- other plugins
  {
    'evanleck/vim-svelte',
    version = 'main',
    ft = 'svelte',
    dependencies = {
      'pangloss/vim-javascript',
      'othree/html5.vim'
    }
  }
})
vim.g.svelte_preprocessors = {'typescript'}

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

5 participants