From be092d6f430ca802d7200e68a5c987195bccd0e9 Mon Sep 17 00:00:00 2001 From: Adam Stankiewicz Date: Thu, 10 Sep 2020 12:18:29 +0200 Subject: Fix jsx indentation, closes #543 --- after/ftplugin/javascript-1.vim | 16 +++ after/ftplugin/javascript-2.vim | 9 ++ after/ftplugin/javascript.vim | 28 +--- after/indent/javascript.vim | 47 ------- after/indent/typescript.vim | 47 ------- packages.yaml | 5 + scripts/build | 31 ++++- syntax/html-1.vim | 94 +++++++++++++ syntax/html-2.vim | 196 +++++++++++++++++++++++++++ syntax/html.vim | 293 +--------------------------------------- 10 files changed, 355 insertions(+), 411 deletions(-) create mode 100644 after/ftplugin/javascript-1.vim create mode 100644 after/ftplugin/javascript-2.vim delete mode 100644 after/indent/typescript.vim create mode 100644 syntax/html-1.vim create mode 100644 syntax/html-2.vim diff --git a/after/ftplugin/javascript-1.vim b/after/ftplugin/javascript-1.vim new file mode 100644 index 00000000..9f6c9314 --- /dev/null +++ b/after/ftplugin/javascript-1.vim @@ -0,0 +1,16 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == -1 + +" Vim filetype plugin file +" Language: JavaScript +" Maintainer: vim-javascript community +" URL: https://github.com/pangloss/vim-javascript + +setlocal iskeyword+=$ suffixesadd+=.js + +if exists('b:undo_ftplugin') + let b:undo_ftplugin .= ' | setlocal iskeyword< suffixesadd<' +else + let b:undo_ftplugin = 'setlocal iskeyword< suffixesadd<' +endif + +endif diff --git a/after/ftplugin/javascript-2.vim b/after/ftplugin/javascript-2.vim new file mode 100644 index 00000000..2992e942 --- /dev/null +++ b/after/ftplugin/javascript-2.vim @@ -0,0 +1,9 @@ +if !exists('g:polyglot_disabled') || (index(g:polyglot_disabled, 'javascript') == -1 && index(g:polyglot_disabled, 'jsx') == -1) + +if get(g:, 'vim_jsx_pretty_disable_js', 0) + finish +endif + +source :h/jsx.vim + +endif diff --git a/after/ftplugin/javascript.vim b/after/ftplugin/javascript.vim index 8ff3938a..e3d355fc 100644 --- a/after/ftplugin/javascript.vim +++ b/after/ftplugin/javascript.vim @@ -1,25 +1,3 @@ -if !exists('g:polyglot_disabled') || (index(g:polyglot_disabled, 'javascript') == -1 && index(g:polyglot_disabled, 'jsx') == -1) - -if get(g:, 'vim_jsx_pretty_disable_js', 0) - finish -endif - -source :h/jsx.vim - -endif -if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'javascript') == -1 - -" Vim filetype plugin file -" Language: JavaScript -" Maintainer: vim-javascript community -" URL: https://github.com/pangloss/vim-javascript - -setlocal iskeyword+=$ suffixesadd+=.js - -if exists('b:undo_ftplugin') - let b:undo_ftplugin .= ' | setlocal iskeyword< suffixesadd<' -else - let b:undo_ftplugin = 'setlocal iskeyword< suffixesadd<' -endif - -endif +" Polyglot metafile +source :h/javascript-1.vim +source :h/javascript-2.vim diff --git a/after/indent/javascript.vim b/after/indent/javascript.vim index 0add1da1..2992e942 100644 --- a/after/indent/javascript.vim +++ b/after/indent/javascript.vim @@ -1,50 +1,3 @@ -if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 - -" Copyright (c) 2016-2020 Jon Parise -" -" Permission is hereby granted, free of charge, to any person obtaining a copy -" of this software and associated documentation files (the "Software"), to -" deal in the Software without restriction, including without limitation the -" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -" sell copies of the Software, and to permit persons to whom the Software is -" furnished to do so, subject to the following conditions: -" -" The above copyright notice and this permission notice shall be included in -" all copies or substantial portions of the Software. -" -" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -" IN THE SOFTWARE. -" -" Language: GraphQL -" Maintainer: Jon Parise - -runtime! indent/graphql.vim - -" Don't redefine our function and also require the standard Javascript indent -" function to exist. -if exists('*GetJavascriptGraphQLIndent') || !exists('*GetJavascriptIndent') - finish -endif - -" Set the indentexpr with our own version that will call GetGraphQLIndent when -" we're inside of a GraphQL string and otherwise defer to GetJavascriptIndent. -setlocal indentexpr=GetJavascriptGraphQLIndent() - -function GetJavascriptGraphQLIndent() - let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val,'name')") - if !empty(l:stack) && l:stack[0] ==# 'graphqlTemplateString' - return GetGraphQLIndent() - endif - - return GetJavascriptIndent() -endfunction - -endif if !exists('g:polyglot_disabled') || (index(g:polyglot_disabled, 'javascript') == -1 && index(g:polyglot_disabled, 'jsx') == -1) if get(g:, 'vim_jsx_pretty_disable_js', 0) diff --git a/after/indent/typescript.vim b/after/indent/typescript.vim deleted file mode 100644 index 968517c8..00000000 --- a/after/indent/typescript.vim +++ /dev/null @@ -1,47 +0,0 @@ -if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'graphql') == -1 - -" Copyright (c) 2016-2020 Jon Parise -" -" Permission is hereby granted, free of charge, to any person obtaining a copy -" of this software and associated documentation files (the "Software"), to -" deal in the Software without restriction, including without limitation the -" rights to use, copy, modify, merge, publish, distribute, sublicense, and/or -" sell copies of the Software, and to permit persons to whom the Software is -" furnished to do so, subject to the following conditions: -" -" The above copyright notice and this permission notice shall be included in -" all copies or substantial portions of the Software. -" -" THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -" IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -" FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -" AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -" LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING -" FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS -" IN THE SOFTWARE. -" -" Language: GraphQL -" Maintainer: Jon Parise - -runtime! indent/graphql.vim - -" Don't redefine our function and also require the standard Typescript indent -" function to exist. -if exists('*GetTypescriptGraphQLIndent') || !exists('*GetTypescriptIndent') - finish -endif - -" Set the indentexpr with our own version that will call GetGraphQLIndent when -" we're inside of a GraphQL string and otherwise defer to GetTypescriptIndent. -setlocal indentexpr=GetTypescriptGraphQLIndent() - -function GetTypescriptGraphQLIndent() - let l:stack = map(synstack(v:lnum, 1), "synIDattr(v:val,'name')") - if !empty(l:stack) && l:stack[0] ==# 'graphqlTemplateString' - return GetGraphQLIndent() - endif - - return GetTypescriptIndent() -endfunction - -endif diff --git a/packages.yaml b/packages.yaml index dfb17252..48367254 100644 --- a/packages.yaml +++ b/packages.yaml @@ -679,6 +679,11 @@ filetypes: --- name: graphql remote: jparise/vim-graphql +after: [javascript, jsx] +ignored_dirs: +# TODO: remove after bug is fixed: +# https://github.com/jparise/vim-graphql/issues/62 +- after/indent filetypes: - name: graphql linguist: GraphQL diff --git a/scripts/build b/scripts/build index 69993374..7503ebff 100755 --- a/scripts/build +++ b/scripts/build @@ -36,6 +36,7 @@ def load_data() end end + puts deps["javascript"] each_node = lambda {|&b| packages.keys.each(&b) } each_child = lambda {|n, &b| deps[n].each(&b) } @@ -168,8 +169,33 @@ def copy_file(package, src, dest) FileUtils.mkdir_p(File.dirname(dest)) name = package.fetch("name") + header = '" Polyglot metafile' + if File.exist?(dest) + meta_dest = dest + new_dest = dest + i = 0 + while File.exist?(new_dest) + i += 1 + new_dest = "#{dest.gsub(/\.vim$/, '')}-#{i}.vim" + end + + if File.read(dest).include?(header) + dest = new_dest + else + FileUtils.mv(dest, new_dest) + File.write(meta_dest, "#{header}\n") + open(meta_dest, "a+") do |output| + output << "source :h/#{File.basename(new_dest)}\n" + end + dest = "#{dest.gsub(/\.vim$/, '')}-#{i+1}.vim" + end + open(meta_dest, "a+") do |output| + output << "source :h/#{File.basename(dest)}\n" + end + end + open(src, "r") do |input| - open(dest, "a+") do |output| + open(dest, "w") do |output| if name == "jsx" output << "if !exists('g:polyglot_disabled') || (index(g:polyglot_disabled, 'javascript') == -1 && index(g:polyglot_disabled, 'jsx') == -1)\n\n" else @@ -335,7 +361,8 @@ def extract(packages) FileUtils.rm_rf(all_dirs) output = [] - packages.map do |package| + # We need to reverse packages so they are included in proper order + packages.reverse.map do |package| repo, branch, path, dir = parse_remote(package["remote"]) dirs = package.fetch("dirs", default_dirs) ignored_dirs = package.fetch("ignored_dirs", []) diff --git a/syntax/html-1.vim b/syntax/html-1.vim new file mode 100644 index 00000000..ddca92d4 --- /dev/null +++ b/syntax/html-1.vim @@ -0,0 +1,94 @@ +if !exists('g:polyglot_disabled') || index(g:polyglot_disabled, 'jinja') == -1 + +" Vim syntax file +" Language: HTML (version 5) +" Maintainer: Rodrigo Machado +" URL: http://rm.blog.br/vim/syntax/html.vim +" Last Change: 2009 Aug 19 +" License: Public domain +" (but let me know if you like :) ) +" +" Note: This file just adds the new tags from HTML 5 +" and don't replace default html.vim syntax file +" +" Modified: othree +" Changes: update to Draft 28 August 2010 +" add complete new attributes +" add wai-aria attributes +" add microdata attributes +" add rdfa attributes + + +syn keyword htmlTagName contained script +" HTML 5 tags +syn keyword htmlTagName contained article aside audio canvas command +syn keyword htmlTagName contained datalist details dialog embed figcaption figure footer +syn keyword htmlTagName contained header hgroup keygen mark meter menu nav output +syn keyword htmlTagName contained progress time ruby rt rp section source summary time track video wbr + +" HTML 5 arguments +" Core Attributes +syn keyword htmlArg contained accesskey class contenteditable contextmenu dir +syn keyword htmlArg contained draggable hidden id lang spellcheck style tabindex title +" Event-handler Attributes +syn keyword htmlArg contained onabort onblur oncanplay oncanplaythrough onchange +syn keyword htmlArg contained onclick oncontextmenu ondblclick ondrag ondragend ondragenter ondragleave ondragover +syn keyword htmlArg contained ondragstart ondrop ondurationchange onemptied onended onerror onfocus onformchange +syn keyword htmlArg contained onforminput oninput oninvalid onkeydown onkeypress onkeyup onload onloadeddata +syn keyword htmlArg contained onloadedmetadata onloadstart onmousedown onmousemove onmouseout onmouseover onmouseup +syn keyword htmlArg contained onmousewheel onpause onplay onplaying onprogress onratechange onreadystatechange +syn keyword htmlArg contained onscroll onseeked onseeking onselect onshow onstalled onsubmit onsuspend ontimeupdate +syn keyword htmlArg contained onvolumechange onwaiting +" XML Attributes +syn keyword htmlArg contained xml:lang xml:space xml:base +" new features +" +syn keyword htmlArg contained onafterprint onbeforeprint onbeforeunload onblur onerror onfocus onhashchange onload +syn keyword htmlArg contained onmessage onoffline ononline onpopstate onredo onresize onstorage onundo onunload +"