diff --git a/autoload/SpaceVim/layers/lang/haxe.vim b/autoload/SpaceVim/layers/lang/haxe.vim index ada5e0b52..5ff6a0ccf 100644 --- a/autoload/SpaceVim/layers/lang/haxe.vim +++ b/autoload/SpaceVim/layers/lang/haxe.vim @@ -51,13 +51,13 @@ let s:haxe_interpreter = 'haxe' function! SpaceVim#layers#lang#haxe#plugins() abort let plugins = [] - call add(plugins, ['jdonaldson/vaxe', { 'merged' : 0}]) + call add(plugins, [g:_spacevim_root_dir . 'bundle/vim-haxe', {'merged' : 0}]) return plugins endfunction function! SpaceVim#layers#lang#haxe#config() abort call SpaceVim#plugins#repl#reg('haxe', s:haxe_interpreter) - call SpaceVim#plugins#runner#reg_runner('haxe', s:haxe_interpreter . ' %s') + call SpaceVim#plugins#runner#reg_runner('haxe', s:haxe_interpreter . ' --main %s --interp') call SpaceVim#mapping#space#regesit_lang_mappings('haxe', function('s:language_specified_mappings')) endfunction diff --git a/bundle/vim-haxe/.gitignore b/bundle/vim-haxe/.gitignore new file mode 100644 index 000000000..80abc5480 --- /dev/null +++ b/bundle/vim-haxe/.gitignore @@ -0,0 +1,2 @@ +.DS_Store +tags diff --git a/bundle/vim-haxe/README.md b/bundle/vim-haxe/README.md new file mode 100644 index 000000000..304b44fc7 --- /dev/null +++ b/bundle/vim-haxe/README.md @@ -0,0 +1,333 @@ +[![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/jdonaldson/vaxe?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) + +Vaxe is a vim bundle for [Haxe][haxe] and [Hss][ncannasse]. It provides support +for syntax highlighting, indenting, compiling, and many more options. Vaxe has +[vimdoc][github], accessible using `:help vaxe` within vim. + +Vaxe requires additional vim features in order to work fully: + +1. Vim version >= 7 : (Vim versions prior to this may work, + but are not tested) +2. Vim with python scripting support : Many default vim environments do not have + python support, but it's typically very easy to get an appropriate version + via a package manager like brew or apt-get. + + +This page will describe some of the special or optional features that vaxe +supports, in addition to recommended configuration settings. + +![Vaxe Screenshot][imgur] (screenshot shows +neocomplcache completion mode, vim-airline, tagbar, and monokai color theme) + +The recommended way to install vaxe is using a bundle management system such +as [pathogen][], [vundle][], [vam][], or [vim-plug][]. + +# Install with Pathogen + +1. Install pathogen using the [instructions][pathogen]. +2. Create/cd into `~/.vim/bundle/` +3. Make a clone of the vaxe repo: + `git clone https://github.com/jdonaldson/vaxe.git` + +To update: + +1. cd into `~/.vim/bundle/vaxe/` +2. git pull + +# Install with Vundle + +1. Install vundle using the [instructions][vundle] +2. Add vaxe to your plugin list in `.vimrc` and re-source it: + `Plugin 'jdonaldson/vaxe'` +3. Run `:PluginInstall` + +To update, just run `:PluginUpdate` + +# Install with VAM + +1. Install VAM using the [instructions][vam] +2. Add vaxe to the list of your activated bundles and re-source it: + `call vam#ActivateAddons(['github:jdonaldson/vaxe'])` + +# Install with vim-plug + +1. Install vim-plug using the [instructions][vim-plug] +2. Add vaxe to your plugin list in `.vimrc` and re-source it: + + insert vaxe + ``` + '' Haxe Plugin + Plug 'jdonaldson/vaxe' + ``` + between + `call plug#begin('~/.vim/plugged')` + + and + `call plug#end()` +3. Run `:PlugInstall` + + +[pathogen]:https://github.com/tpope/vim-pathogen + +[vundle]:https://github.com/gmarik/vundle + +[vam]:https://github.com/MarcWeber/vim-addon-manager + +[vim-plug]:https://github.com/junegunn/vim-plug + +# Compiling Haxe Projects with vaxe + +## HXML File Support +Vaxe supports [hxml build files][haxe 2], which provide +all of the arguments for the compiler, similar to a [make +file][wikipedia]. + +Vaxe will automatically try to determine the appropriate hxml file you are +using. It will also let you easily override this with a specific file +(see vim docs for more details). + +Vaxe will specify a custom +[makeprg][sourceforge] using +the given hxml file. The makeprg will cd to the directory containing the hxml, +execute the haxe compiler with the hxml file, and pipe output to stdout. + +If vaxe has found your build file, you can just run the make command: + +```viml +:make +``` + +Vaxe will also specify an +[errorformat][sourceforge 2], +so that errors and trace messages show up in the +[quickfix][sourceforge 3] +window. + +## Lime Project Support +![Lime][imgur 2] + +Vaxe supports [Lime][github 2] +workflows. If a Lime project is found, Vaxe will use it for builds and +completions. You can specify a default target if you only work with one +platform. + +## Flow Project Support + +Vaxe supports [Flow][github 13] +workflows. If a flow project is found, Vaxe will use it for builds and +completions. You can specify a default target if you only work with one +platform. + +## Omni-completions + +Vaxe provides an +[omnicompletion][sourceforge 4] +function that can use the haxe compiler in order to [display field +completions][haxe 3]. Visual Studio users will +recognize this as being similar to "intellisense". + +You can trigger an omnicompletion (C-X C-O in Insert Mode) after the period at +the start of a field, submodule, or class access, or after the first +parentheses of a function invocation. See the [haxe +documentation][haxe 3] for more details. + +### Active Targets: Dealing with --next + +In some cases, an hxml file may specify multiple targets via a `--next` +directive. Vaxe will use the first target it finds in order to generate +completions. It is possible to specify a different target by +inserting a line like this into your hxml: + + # display completions + +If Vaxe finds that line, it will use that target to generate completions and +perform other miscellaneous tasks. The target that Vaxe uses is called the +"active" target here. + +# HSS Support +Vaxe will also support the [hss][ncannasse] language, +with support for syntax highlighting, and compilation to css. + +# Recommended Plugins/Additions/Config + +Vaxe will work fine on its own, but it is designed to integrate cleanly with +a number of other bundles and plugins. Once again, it is recommended to use +pathogen, vundle, or vam to manage installation and updates. + +## Misc Config +Vaxe provides a full completion specification for vim, which includes providing +function documentation via the [preview +window]( http://vimdoc.sourceforge.net/htmldoc/windows.html#preview-window ). +This can be turned off with: + +```viml +set completeopt=menu +``` + +This will only use the menu, and not the preview window. See ```:help +preview-window``` for more details. + +Also, it is recommended that ```autowrite``` is set for haxe/hxml files. +Otherwise, completions will not be available as you type. See ```help +autowrite``` for more details. If autowrite is not set, Vaxe will return an +error message when completions are requested. It is possible to turn this off, +see the help for g:vaxe_completion_require_autowrite. + +## Airline + +Airline ( [by Bailey Ling][github 3]) is a handy +[status line][sourceforge 5] +replacement. I think it looks better, and provides a good deal more +functionality over a normal status line setting. Airline support is provided by +default in vaxe. Current support enables the display of the current hxml build +file. The hxml name has an empty star if it's in default mode (☆ ), and a +filled star if it's in project mode (★ ). You can disable all of this by +changing ```g:vaxe_enable_airline_defaults``` to 0. + +Personally, I'm perfectly happy using airline, but If you're looking for support +for the original [powerline][github 4], you can +check [my repo][github 5]. The original +powerline version is more powerful, but much more difficult to install and +configure. Copy the configuration information from my linepower repo instead of +the configuration information from the main powerline repo in order to enable +the vaxe plugin. + +## Tags + +Vim has great support for +[ctags][sourceforge 6], which are really +useful for navigating a large code base. + +You'll need to define some patterns for ctags in order for it to work with +Haxe. Put these lines in your `.ctags` file in your home directory: + +```bash +--langdef=haxe +--langmap=haxe:.hx +--regex-haxe=/^[ \t]*((@:?[a-zA-Z]+)[ \t]+)*((inline|macro|override|private|public|static)[ \t]+)*function[ \t]+([A-Za-z0-9_]+)/\5/f,function/ +--regex-haxe=/^[ \t]*((@:?[a-zA-Z]+)[ \t]+)*((inline|private|public|static)[ \t]+)*var[ \t]+([A-Za-z0-9_]+)/\5/v,variable/ +--regex-haxe=/^[ \t]*package[ \t]*([A-Za-z0-9_\.]+)/\1/p,package/ +--regex-haxe=/^[ \t]*((@:?[a-zA-Z]+)[ \t]+)*((extern|private)[ \t]+)?abstract[ \t]+([A-Za-z0-9_]+)[ \t]*[^\{]*/\5/a,abstract/ +--regex-haxe=/^[ \t]*((@:?[a-zA-Z]+)[ \t]+)*((extern|private)[ \t]+)?class[ \t]+([A-Za-z0-9_]+)[ \t]*[^\{]*/\5/c,class/ +--regex-haxe=/^[ \t]*((@:?[a-zA-Z]+)[ \t]+)*((extern|private)[ \t]+)?interface[ \t]+([A-Za-z0-9_]+)/\5/i,interface/ +--regex-haxe=/^[ \t]*((private)[ \t]+)?typedef[ \t]+([A-Za-z0-9_]+)/\3/t,typedef/ +--regex-haxe=/^[ \t]*enum[ \t]+([A-Za-z0-9_]+)/\1/e,enum/ +``` + +Vaxe can generate a set of tags specific to the given build by running: + vaxe#Ctags() +This will feed the paths used by the compiler into ctags. Only the relevant +paths for the current target will be used. + +Other utilities, like vaxe#ImportClass() can then use this tag information in +order to programmatically import classes. E.g. calling vaxe#ImportClass on +this line: + +```haxe + var l = new haxe.ds.StringMap(); +``` + +will generate: + +```haxe + import haxe.ds.StringMap; + ... + var l = new StringMap(); +``` + +Keep in mind that jumping to files defined by ctags may jump to a location +outside of the current working directory. If you want to keep the reference +to you current hxml file when doing so, it is advised that you select a project +mode hxml with ```:ProjectHxml```. + +## Tagbar + +Using the ctags lines above, the +[Tagbar][github 6] bundle can display a nice +overview of the classes, methods, and variables in your current haxe file. You +do not need to call `vaxe#Ctags()` in order to use Tagbar, it works +automatically, but only for the current vaxe buffer. + +## Syntastic + +[Syntastic][github 7] is a popular bundle that +enables syntax errors to be displayed in a small gutter on the left of the +editor buffer. I've patched Syntastic to use vaxe compilation information for +haxe and hss, including errors and traces. All that is necessary is to install +the bundle. + + +## YouCompleteMe +[YouCompleteMe][github 8] (YCM) is a bundle that +provides completions for c-style languages. However, it has the ability to +provide support for other languages as well, such as the completion methods +provided through vaxe. Vaxe will let YCM use its completion methods +automatically, all that is required is that YCM (and its libraries) be compiled +and installed. + +## Autocomplpop +[AutoComplPop][vim] is an +older vim script that automatically pops up a completion menu when an +omnicompletion is available. It should offer good basic completions using +pure vimscript. Vaxe will let ACP use its completion methods automatically. + +## Neocomplcache +[Neocomplcache][github 9] is a plugin for vim +that can manage virtually any type of completion (omni, keyword, file, etc). It +can be tricky to set up, so follow their documentation carefully. + +# Acknowledgements +* [Marc Weber][github 14] : Most of the early work for the bundle was +based off of his [vim-haxe bundle][github 10]. +Some of the hss functionality comes from his work on +[scss-vim][github 11]. + +* [Ganesh Gunasegaran][github 15] : I based my hxml syntax file off of [his +version][motion-twin]. + +* [Laurence Taylor][github 16] : I based my ctags description of of [his mailing list post] +[haxe 4] + +* [Luca Deltodesco][github 17] : The main Haxe syntax file is based +off of [his version][github 12]. + +* [Roger Duran][github 18] : Provided suport for +[flow][github 19] + + + +[github]: https://raw.github.com/jdonaldson/vaxe/master/doc/vaxe.txt +[github 10]: https://github.com/MarcWeber/vim-haxe +[github 11]: https://github.com/cakebaker/scss-syntax.vim +[github 12]: https://gist.github.com/deltaluca/6330630 +[github 13]: https://underscorediscovery.github.io/flow/ +[github 14]: https://github.com/MarcWeber +[github 15]: https://github.com/itsgg +[github 16]: https://github.com/0b1kn00b +[github 17]: https://github.com/deltaluca +[github 18]: https://github.com/Roger +[github 19]: https://github.com/underscorediscovery/flow +[github 2]: https://github.com/openfl/lime +[github 3]: https://github.com/bling/vim-airline +[github 4]: https://github.com/Lokaltog/powerline +[github 5]: https://github.com/jdonaldson/linepower.vim +[github 6]: http://majutsushi.github.com/tagbar/ +[github 7]: https://github.com/scrooloose/syntastic +[github 8]: https://github.com/Valloric/YouCompleteMe +[github 9]: https://github.com/Shougo/neocomplcache +[haxe]: http://www.haxe.org +[haxe 2]: http://haxe.org/doc/compiler +[haxe 3]: http://haxe.org/manual/completion +[haxe 4]: http://haxe.org/forum/thread/3395#nabble-td3443583 +[imgur]: http://i.imgur.com/JFvze.png +[imgur 2]: http://i.imgur.com/rc8vLi2.png +[motion-twin]: http://lists.motion-twin.com/pipermail/haxe/2008-July/018220.html +[ncannasse]: http://ncannasse.fr/projects/hss +[sourceforge]: http://vimdoc.sourceforge.net/htmldoc/options.html#'makeprg' +[sourceforge 2]: http://vimdoc.sourceforge.net/htmldoc/options.html#'errorformat' +[sourceforge 3]: http://vimdoc.sourceforge.net/htmldoc/quickfix.html#quickfix +[sourceforge 4]: http://vimdoc.sourceforge.net/htmldoc/version7.html#new-omni-completion +[sourceforge 5]: http://vimdoc.sourceforge.net/htmldoc/windows.html#status-line +[sourceforge 6]: http://vimdoc.sourceforge.net/htmldoc/tagsrch.html +[vim]: http://www.vim.org/scripts/script.php?script_id=1879 +[wikipedia]: http://en.wikipedia.org/wiki/Make_(software) diff --git a/bundle/vim-haxe/autoload/vaxe.vim b/bundle/vim-haxe/autoload/vaxe.vim new file mode 100644 index 000000000..251ec88d2 --- /dev/null +++ b/bundle/vim-haxe/autoload/vaxe.vim @@ -0,0 +1,669 @@ +let unsupported_msg = 'Unsupported platform, send a note to the maintainer about adding support' + +function! vaxe#SetWorkingDir() + exe 'cd "'.g:vaxe_working_directory.'"' +endfunction + +" Utility logging function +function! vaxe#Log(str) + if g:vaxe_logging + echomsg a:str + endif +endfunction + +function! vaxe#CurrentTarget() + if exists("g:vaxe_lime_target") + return "g:vaxe_lime_target" + elseif exists("g:vaxe_flow_target") + return "g:vaxe_flow_target" + else + return '' + endif +endfunction + +" Utility function to open the hxml file that vaxe is using. +function! vaxe#OpenHxml() + let vaxe_hxml = vaxe#CurrentBuild() + if filereadable(vaxe_hxml) + exe ':edit '.fnameescape(vaxe_hxml) + else + echoerr 'build not readable: '.vaxe_hxml + endif +endfunction + +" Generate a nicely formatted build file name for powerline, etc. +function! vaxe#CurrentBuildPowerline() + let short_name = fnamemodify(vaxe#CurrentBuild(), ":.") + if len(short_name) > 0 + let short_name = "☢ " . short_name + endif + return short_name +endfunction + +function! vaxe#KillCacheServer() + if has('unix') + call system("kill ". g:vaxe_cache_server_pid) + unlet g:vaxe_cache_server_pid + else + echoerr unsupported_msg + endif +endfunction + +function! vaxe#StartCacheServer() + if has('unix') + let haxe_version = vaxe#util#HaxeServerVersion() + if haxe_version != '0' + echomsg "Compilation server is already running on port " + \ . g:vaxe_cache_server_port + else + let pid = vaxe#util#SimpleSystem(g:vaxe_haxe_binary . " --wait " + \. g:vaxe_cache_server_port . "& echo $!") + if pid =~ '\v[0-9]+' + let g:vaxe_cache_server_pid = pid + echomsg "Started a haxe compilation cache server on port " + \ . g:vaxe_cache_server_port + \ . " with pid " . g:vaxe_cache_server_pid + autocmd VimLeavePre * call vaxe#KillCacheServer() + else + echoerr "Could not start haxe cache server." + \. "See docs for more details." + \. "(help vaxe-cache-server)" + endif + endif + else + echoerr unsupported_msg + endif +endfunction + +" Utility function that tries to 'do the right thing' in order to import a +" given class. Call it on a given line in order to import a class definition +" at that line. E.g. +" var l = new haxe.FastList() +" becomes +" import haxe.FastList; +" ... +" var l = new FastList(); +" You can also call this without a package prefix, and vaxe will try to look +" up packages that contain the (e.g. FastList) class name. +function! vaxe#ImportClass() + let match_parts = matchlist(getline('.'), '\(\(\l\+\.\)\+\)*\(\u\w*\)') + if len(match_parts) + let package = match_parts[1] + " get rid of the period at the end of the package declaration. + let package = substitute(package, "\.$",'','g') + let class = match_parts[3] + if search("^\\s*import\\s*\\(\\a\\+\\.\\)*".class, 's') > 0 + echomsg "Class has already been imported" + return + endif + let file_packages = {} + let file_classes = {} + + if package == '' + for val in taglist(".") + if val['kind'] == 'p' + let file_packages[val['filename']] = val['name'] + elseif val['kind'] == 'c' || val['kind'] == 't' || val['kind'] == 'i' + if val['name'] == class + let file_classes[val['filename']] = val['name'] + endif + endif + endfor + + let packages = [] + + for file in keys(file_classes) + if has_key(file_packages, file) + let packages = packages + [file_packages[file]] + endif + endfor + + if len(packages) == 0 + echomsg "No packages found in ctags" + return + endif + + let package = packages[0] + if len(packages) > 1 + let package = vaxe#util#InputList("Select package", packages) + endif + endif + + if package == '' + echomsg "No package found for class" + return + endif + let oldpos = getpos('.') + + let importline = search("^\\s*import") + if importline == 0 + let importline = search("^\\s*package") + endif + call cursor(oldpos[1], oldpos[2]) + let fixed = substitute(getline('.'), package.'\.', '','g') + call setline(line('.'), fixed) + call append(importline,['import '.package.'.'.class.';']) + call cursor(oldpos[1]+1, oldpos[2]) + endif +endfunction + +" A function suitable for omnifunc +function! vaxe#HaxeComplete(findstart, base) + " ERROR: no python + if !has("python") && !has("python3") + echoerr 'Vaxe requires python for completions' + return [] + endif + + " EXIT: trace does not have function argument completion + let linepart = strpart(getline('.'), 0, col('.')) + if match(linepart, "trace($") > 0 + return [] + endif + + " EXIT: comments/constants shouldn't be completed + let syntax_type = synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") + if syntax_type == 'Comment' || syntax_type == 'Constant' + return [] + endif + + call s:HandleWriteEvent() + + if a:findstart + let line = getline('.') + let period = strridx(line, '.') + let paren = strridx(line, '(') + if (period == paren) + return -1 + endif + let basecol = max([period,paren]) + 1 + return basecol + else + return s:FormatDisplayCompletion(a:base) + endif +endfunction + + +" A function that will search for valid hxml in the current working directory +" and allow the user to select the right candidate. The selection will +" enable 'project mode' for vaxe. +function! vaxe#ProjectHxml(...) + if exists('g:vaxe_hxml') + unlet g:vaxe_hxml + endif + + let g:vaxe_working_directory = getcwd() + + if a:0 > 0 && a:1 != '' + let g:vaxe_hxml = expand(a:1,':p') + else + let hxmls = split(glob("**/*.hxml"),'\n') + if len(hxmls) == 0 + echoerr "No hxml files found in current working directory" + return + else + let base_hxml = vaxe#util#InputList("Select Hxml", hxmls) + endif + + if base_hxml !~ "^\([a-zA-Z]:\)\=[/\\]" + let base_hxml = getcwd() . '/' . base_hxml + endif + let g:vaxe_hxml = base_hxml + endif + if !filereadable(g:vaxe_hxml) + echoerr "Project build file not valid, please create one." + return + endif + call vaxe#SetCompiler() + return g:vaxe_hxml +endfunction + + +" A function that runs on a hx filetype load. It will set the default hxml +" path if the project hxml or lime are not set. +function! vaxe#AutomaticHxml() + if exists ("g:vaxe_lime") + call vaxe#lime#ProjectLime(g:vaxe_lime) + elseif exists ("g:vaxe_flow") + call vaxe#flow#ProjectFlow(g:vaxe_flow) + elseif exists('g:vaxe_hxml') + call vaxe#ProjectHxml(g:vaxe_hxml) + elseif exists('g:vaxe_skip_hxml') + return + else + call vaxe#DefaultHxml() + endif +endfunction + +" A function that sets the default hxml located in the parent directories of +" the current buffer. +function! vaxe#DefaultHxml(...) + " unlet any existing hxml variables + if exists('b:vaxe_hxml') + unlet b:vaxe_hxml + endif + + "First check if an hxml/lime/flow was passed explicitly + if a:0 > 0 && a:1 != '' + if match(a:1,'\.hxml$') + let b:vaxe_hxml = a:1 + elseif match(a:1,'\.xml$') + let g:vaxe_lime = a:1 + elseif match(a:1,'\.lime$' ) + let g:vaxe_lime = a:1 + elseif match(a:1,'\.flow$' ) + let g:vaxe_flow = a:1 + endif + else " check if there's a lime/flow in the parent roots... + let base_build = vaxe#util#ParentSearch( + \ g:vaxe_default_parent_search_patterns + \ , fnamemodify(expand("%"),":p:h")) + if (base_build != '') + let base_builds = split(base_build,'\n') + if g:vaxe_prefer_first_in_directory + let base_build = base_builds[0] + else + let base_build = vaxe#util#InputList("Select build file", base_builds) + endif + if base_build !~ '^\([a-zA-Z]:\)\=[/\\]' + let base_build = getcwd() . '/' . base_build + endif + + if base_build =~ '\.lime' || base_build =~ '\.xml' + let b:vaxe_lime = base_build + call vaxe#lime#BuildLimeHxml(b:vaxe_lime) + elseif base_build =~ '\.xml' + let b:vaxe_lime = base_build + call vaxe#lime#BuildLimeHxml(b:vaxe_lime) + elseif base_build =~ '\.flow' + let b:vaxe_flow = base_build + call vaxe#flow#BuildFlowHxml(b:vaxe_flow) + else + let b:vaxe_hxml = base_build + endif + end + endif + + if !exists('b:vaxe_hxml') + let b:vaxe_hxml = '' + endif + + if !filereadable(b:vaxe_hxml) + if b:vaxe_hxml == expand("%") + " hxml has been opened, but not written yet + " Set an autocmd to set the hxml after the buffer is written + augroup temp_hxml + autocmd BufWritePost call vaxe#DefaultHxml(expand("%"))| autocmd! temp_hxml + augroup END + else + redraw + echomsg "Default build file not valid: " . b:vaxe_hxml + endif + return + endif + + let g:vaxe_working_directory = fnamemodify(b:vaxe_hxml, ":p:h") + + " set quickfix to jump to working directory before populating list + " this is necessary since use may cd to different directories during + " session + autocmd QuickFixCmdPre exe 'cd ' . fnameescape(g:vaxe_working_directory) + autocmd QuickFixCmdPost cd - + + call vaxe#SetCompiler() +endfunction + + +" Returns the hxml file that should be used for compilation or completion +function! vaxe#CurrentBuild() + let vaxe_hxml = '' + if exists('g:vaxe_hxml') + let vaxe_hxml = g:vaxe_hxml + elseif exists('b:vaxe_hxml') + let vaxe_hxml = b:vaxe_hxml + endif + return vaxe_hxml +endfunction + +" Sets the makeprg +function! vaxe#SetCompiler() + if !g:vaxe_set_makeprg + return + endif + let abspath = [] + let escaped_wd = fnameescape(g:vaxe_working_directory) + let dirs = split(&tags, ",") + if !match(dirs, g:vaxe_working_directory) + let &tags = &tags . ',' . g:vaxe_working_directory + endif + + if exists("g:vaxe_lime") || exists("b:vaxe_lime") + let build_verb = "build" + if g:vaxe_lime_test_on_build + let build_verb = "test" + endif + let build_command = "cd " . escaped_wd . " && " + \."lime ".build_verb." ". g:vaxe_lime_target . " 2>&1" + elseif exists("g:vaxe_flow") || exists("b:vaxe_flow") + let build_command = "cd " . escaped_wd . " && " + \."haxelib run flow build " . g:vaxe_flow_target . " 2>&1" + else + let vaxe_hxml = vaxe#CurrentBuild() + let escaped_hxml = fnameescape(vaxe_hxml) + call vaxe#Log("vaxe_hxml: " . vaxe_hxml) + let build_command = "cd " . escaped_wd ." &&" + \. g:vaxe_haxe_binary . " " . escaped_hxml . " 2>&1" + if filereadable(vaxe_hxml) + let lines = readfile(vaxe_hxml) + endif + endif + + let &l:makeprg = build_command + let &l:errorformat="%W%f:%l: characters %c-%*[0-9] : Warning : %m + \,%E%f:%l: characters %c-%*[0-9] : %m + \,%E%f:%l: lines %*[0-9]-%*[0-9] : %m" + + " if g:vaxe_trace_absolute_path is specified, then traces contain useful + " path information, and errorfmt can use it to jump to the file/folder + " location + if (g:vaxe_trace_absolute_path) + let &l:errorformat .= ",%I%f:%l: %m" + endif + " generic catch-all regex that will grab misc stdout + let &l:errorformat .= ",%I%m" +endfunction + +" returns a list of compiler class paths +function! vaxe#CompilerClassPaths() + let output_phrase = "\n--no-output" + if g:vaxe_completion_write_compiler_output + let output_phrase = "" + endif + let complete_args = vaxe#CurrentBlockHxml() + let complete_args.= "\n"."-v".output_phrase + let complete_args = join(split(complete_args,"\n"),' ') + let vaxe_hxml = vaxe#CurrentBuild() + let hxml_cd = fnameescape(fnamemodify(vaxe_hxml,":p:h")) + let hxml_sys = "cd\ ".hxml_cd."; " . g:vaxe_haxe_binary . " ".complete_args."\ 2>&1" + let voutput = system(hxml_sys) + let raw_path = split(voutput,"\n")[0] + let raw_path = substitute(raw_path, "Classpath :", "","") + let paths = split(raw_path,';') + let paths = filter(paths,'v:val != "/" && v:val != ""') + if len(paths) == 1 + echoerr "The compiler exited with an error: ". paths[0] + return [] + endif + let unique_paths = vaxe#util#UniqueList(paths) + return unique_paths +endfunction + +" Calls ctags on the list of compiler class paths +function! vaxe#Ctags() + let paths = vaxe#CompilerClassPaths() + + if (len(paths) > 0) + let fixed_paths = [] + for p in paths + " escape spaces in paths + let p = fnameescape(p) + if p =~ "/std/$" + "this is the target std dir. We need to alter use it to add some + "global std utility paths, and avoid the target paths. + let fixed_paths = fixed_paths + [p.'haxe/', p.'sys/', p.'tools/', p.'*.hx'] + elseif p =~ "/_std/$" + "this is the selected target paths, we can exclude the _std path + "that includes target specific implementations of std classes. + let p = substitute(p, "_std/$", "","g") + let fixed_paths = fixed_paths + [p] + elseif p =~ "^\./$" + "this is an alt representation of the working dir, we don't + "need it + continue + else + "this is a normal path (haxelib, or via -cp) + let fixed_paths = fixed_paths + [p] + endif + endfor + + let pathstr = join( fixed_paths,' ') + let vaxe_hxml = vaxe#CurrentBuild() + " get the hxml name so we can cd to its directory + " TODO: this probably needs to be user specified + let hxml_cd = fnamemodify(vaxe_hxml,":p:h") + let hxml_cd = substitute(hxml_cd, " ", "\\\\ ", "g") + " call ctags recursively on the directories + let hxml_sys = " cd " . hxml_cd . ";" + \." ctags --languages=haxe --exclude=_std -R " . pathstr. ";" + call vaxe#Log(hxml_sys) + call system(hxml_sys) + endif +endfunction + + +" Generate inline compiler declarations for the given target from the relevant +" build hxml string. Remove any flags that generate unnecessary output or activity. +function! s:CurrentBlockHxml(hxml_str) + let parts = split(a:hxml_str, '--next') + + if len(parts) == 0 + let parts = [a:hxml_str] + endif + + let complete = filter(copy(parts), 'v:val =~ "#\\s*display completions"') + if len(complete) == 0 + let complete = parts + endif + let result = complete[0] + + " add some optional hxml commands that are useful for vaxe + if (g:vaxe_trace_absolute_path) + let result = result . "\n-D absolute_path" + endif + if (g:vaxe_completion_disable_optimizations) + let result = result . "\n-D no-copt" + endif + + let result = result . "\n-D --no-output" + + return s:SanitizeHxml(result) +endfunction + + +" clean up hxml in string form by removing -(cmd|v|xml) directives +" also escape spaces in arguments +function! s:SanitizeHxml(complete_string) + let parts = split(a:complete_string,"\n") + let fixed = [] + + for p in parts + let p = substitute(p, '#.*','','') " strip comments + let p = substitute(p, '\s*$', '', '') " strip trailing ws + + " strip cmd\xml\verbose\times directives + let p = substitute(p, '^\s*-\(cmd\|xml\|v\|-times\)\s*.*', '', '') + + " fnameescape directives + let p = substitute(p, '^\s*\(--\?[a-z0-9\-]\+\)\s*\(.*\)$', '\=submatch(1)." ".escape(fnameescape(submatch(2)), "()")', '') + + call add(fixed, p) + endfor + + return join(fixed,"\n") +endfunction + + + + +function! vaxe#CurrentBuildPlatform() + let block = vaxe#CurrentBlockHxml() + if (block =~ "-as3") + return "as3" + elseif (block =~ "-cpp") + return "cpp" + elseif (block =~ "-cs") + return "cs" + elseif (block =~ "-js") + return "js" + elseif (block =~ "-java") + return "java" + elseif (block =~ "-swf") + return "swf" + elseif (block =~ "-php") + return "php" + elseif (block =~ "-py") + return "python" + elseif (block =~ "-lua") + return "lua" + elseif (block =~ "-hl") + return "hashlink" + elseif (block =~ "-neko" || block =~ "-x ") + return "neko" + else + return "unknown" + endif +endfunction + + + +function! vaxe#CurrentBlockHxml() + let vaxe_hxml = vaxe#CurrentBuild() + if (!filereadable(vaxe_hxml)) + return '' + endif + let hxml_str = join(readfile(vaxe_hxml),"\n") + return s:CurrentBlockHxml(hxml_str) +endfunction + +" Returns hxml that is suitable for making a --display completion call +function! s:CompletionHxml(file_name, byte_count) + " the stripped down haxe compiler command (no -cmd, etc.) + let stripped = vaxe#CurrentBlockHxml() + if (g:vaxe_cache_server) + " let stripped \. stripped " the stripped hxml + let stripped = "--cwd " . fnameescape(g:vaxe_working_directory) + \. " \n--connect " + \. g:vaxe_cache_server_port + \. " \n" . stripped + endif + return stripped."\n--display ".fnameescape(a:file_name).'@'.a:byte_count +endfunction + +if g:vaxe_haxe_version >=3 +function! vaxe#JumpToDefinition() + let output = [] + let extra = "\n-D display-mode=position" + let complete_output = s:RawCompletion(b:vaxe_hxml, extra) + " execute the python completion script in autoload/vaxe.py + call vaxe#Log(complete_output) + exec g:vaxe_py . "locations('complete_output','output')" + let output_str = join(output, '\n') + lexpr(output_str) +endfunction +endif + +" ignore the write requests generated by completions +function! s:HandleWriteEvent() + let events = '' + let old_ignore = &l:eventignore + if (g:vaxe_completion_prevent_bufwrite_events) + let events = "BufWritePost,BufWritePre,BufWriteCmd" + endif + + if (&l:eventignore) + let &l:eventignore = &l:eventignore . ',' . events + else + let &l:eventignore = events + endif + + if (&autowriteall) + exe ":silent wall" + elseif (&autowrite) + exe ":silent update" + endif + + let &l:eventignore = old_ignore +endfunction + +" a 'raw completion' function that will just return unformatted output +" pass extra string options to append to the current hxml +function! s:RawCompletion(vaxe_hxml, extra_string) + let offset = line2byte('.') + col('.') -2 + " handle the BOM + if &bomb + let offset += 3 + endif + + let complete_args = s:CompletionHxml(expand("%:p"), offset) + let complete_args = complete_args . ' ' . a:extra_string + + let hxml_cd = "cd\ \"".fnamemodify(a:vaxe_hxml,":p:h"). "\"" + if has('win32') + let hxml_cd = hxml_cd. "&" + else + let hxml_cd = hxml_cd. ";" + endif + if exists("g:vaxe_hxml") + let hxml_cd = '' + endif + + let hxml_sys = hxml_cd." " . g:vaxe_haxe_binary ." ".complete_args."\ 2>&1" + let hxml_sys = join(split(hxml_sys,"\n")," ") + call vaxe#Log(hxml_sys) + let complete_output = system(hxml_sys) + return complete_output +endfunction + +" Shows an error result in the completion list. Or, if this isn't possible, +" shows a normal error +function! s:ShowCompletionError(title, msg) + if(&cot =~ 'menuone') + return [{"word" : "", "abbr" : a:title, "menu" : a:msg, "empty" : 1}] + else + echoerr a:title.' '.a:msg + return [] + endif +endfunction + +" The main completion function that invokes the compiler, etc. +function! s:FormatDisplayCompletion(base) + if g:vaxe_completion_require_autowrite && !(&autowrite || &autowriteall) + return s:ShowCompletionError("Vim configuration error: ", "Please ':set autowrite' for haxe completion to work properly ") + endif + let vaxe_hxml = vaxe#CurrentBuild() + if !filereadable(vaxe_hxml) + return s:ShowCompletionError("Compiler error: ", "No valid build file") + endif + let complete_output = s:RawCompletion(vaxe_hxml, '') + " quick and dirty check for error + let tag = complete_output[1:4] + if tag != "type" && tag != "list" && tag != "pos>" + let error = complete_output[:len(complete_output)-2] + if type(error) != type("") + return s:ShowCompletionError("Compiler error: ", "No valid output was received from completion request") + endif + cgete error + return s:ShowCompletionError( "Compiler error: ", error) + endif + let output = [] + call vaxe#Log('compiler output: ' . complete_output) + + " execute the python completion script in autoload/vaxe.py + execute g:vaxepy . "complete('complete_output','output' + \, 'a:base', 'g:vaxe_completion_alter_signature' + \, 'g:vaxe_completion_collapse_overload')" + + call vaxe#Log("display elements: " . len(output)) + for o in output + let tag = '' + if has_key(o,'info') + let o['info'] = join(o['info'],"\n") + endif + if has_key(o,'menu') + let o['info'] = o['info'] . "\n " . o['menu'] + endif + endfor + + return output +endfunction + diff --git a/bundle/vim-haxe/autoload/vaxe/flow.vim b/bundle/vim-haxe/autoload/vaxe/flow.vim new file mode 100644 index 000000000..3b9b832c6 --- /dev/null +++ b/bundle/vim-haxe/autoload/vaxe/flow.vim @@ -0,0 +1,109 @@ +function! vaxe#flow#Targets(...) + return s:flow_targets +endfunction + +function! vaxe#flow#ProjectFlow(...) + if exists('g:vaxe_flow') + unlet g:vaxe_flow + endif + let g:vaxe_working_directory = getcwd() + + if a:0 > 0 && a:1 != '' + let g:vaxe_flow = expand(a:1,':p') + else + let flows = split(glob("**/*.flow"),'\n') + + if len(flows) == 0 + echoerr "No flow/openfl project files found in current working directory" + return + endif + + let base_flow = vaxe#util#InputList("Select flow", flows) + + if base_flow !~ "^\([a-zA-Z]:\)\=[/\\]" + let base_flow = getcwd() . '/' . base_flow + endif + + echomsg 'Project flow selected: ' . base_flow + + let g:vaxe_flow = base_flow + endif + if !filereadable(g:vaxe_flow) + echoerr "Project flow file not valid, please create one." + return + endif + call vaxe#flow#BuildFlowHxml(g:vaxe_flow) + call vaxe#SetCompiler() + return g:vaxe_flow +endfunction + +function! vaxe#flow#Clean(...) + if (a:0 && a:1 != '') + let target = split(a:1)[0] + else + let target = g:vaxe_flow_target + endif + let command = "flow clean ".target + call vaxe#Log(command) + call s:Sys(command) +endfunction + +function! vaxe#flow#RebuildHxml() + if exists("b:vaxe_flow") + call vaxe#flow#BuildFlowHxml(b:vaxe_flow) + endif +endfunction + +"A simple system function that first changes directory to the current vaxe +"working directory +function! s:Sys(cmd) + call system("cd ".g:vaxe_working_directory." && ".a:cmd) +endfunction + +function! vaxe#flow#BuildFlowHxml(flow) + let base_hxml = a:flow.".hxml" + + if !strlen(g:vaxe_flow_target) + call vaxe#flow#Target(a:flow) + endif + + let g:vaxe_working_directory = fnamemodify(a:flow, ":p:h") + let cdcmd = 'cd "'.fnameescape(g:vaxe_working_directory).'" && ' + + "create the flow.hxml if not present + if !filereadable(base_hxml) + " pipe flow display to an hxml for completions + let escape_base = fnameescape(base_hxml) + call s:Sys(" echo '# THIS FILE IS AUTOGENERATED BY VAXE, ANY EDITS ARE DISCARDED' " . " > " . escape_base) + call s:Sys(" haxelib run flow info " . g:vaxe_flow_target . " --hxml " + \. " >> " . escape_base ) + endif + + let b:vaxe_hxml = base_hxml + " let g:vaxe_hxml = b:vaxe_hxml " don't set a global projet var by default +endfunction + +"Sets the target. If target is missing it asks the user. Also updates the +"makeprg compiler command +function! vaxe#flow#Target(flow, ...) + let g:vaxe_flow_target = '' + if a:0 > 1 && a:2 != '' + let g:vaxe_flow_target = a:2 + else + let g:vaxe_flow_target = vaxe#util#InputList("Select flow Target", s:flow_targets) + let g:vaxe_flow_target = split(g:vaxe_flow_target, ":")[0] + endif + call vaxe#flow#BuildFlowHxml(a:flow) + call vaxe#SetCompiler() +endfunction + +" A list of all the flow targets +let s:flow_targets = [ "android : Create Google Android applications" + \, "web : Create HTML5 webgl applications" + \, "ios : Create Apple iOS applications" + \, "linux --arch 32 : Create Linux 32-bit applications" + \, "linux --arch 64 : Create Linux 64-bit applications" + \, "mac --arch 32 : Create Apple Mac OS X 32-bit applications" + \, "mac --arch 64 : Create Apple Mac OS X 64-bit applications" + \, "windows --arch 32 : Create Microsoft Windows 32-bit applications" + \, "windows --arch 64 : Create Microsoft Windows 64-bit applications"] diff --git a/bundle/vim-haxe/autoload/vaxe/hss.vim b/bundle/vim-haxe/autoload/vaxe/hss.vim new file mode 100644 index 000000000..c52be8117 --- /dev/null +++ b/bundle/vim-haxe/autoload/vaxe/hss.vim @@ -0,0 +1,39 @@ +" Taken from Marc Weber's scss indent script: +" https://github.com/cakebaker/scss-syntax.vim/blob/master/autoload/scss_indent.vim +" usage: +" set indentexpr=scss_indent#GetIndent(v:lnum) +fun! vaxe#hss#GetIndent(lnum) + " { -> increase indent + " } -> decrease indent + if a:lnum == 1 + " start at 0 indentation + return 0 + endif + + " try to find last line ending with { or } + " ignoring // comments + let regex = '\([{}]\)\%(\/\/.*\)\?$' + let nr = search(regex, 'bnW') + if nr > 0 + let last = indent(nr) + let m = matchlist(getline(nr), regex) + let m_curr = matchlist(getline(a:lnum), regex) + echoe string(m).string(m_curr) + if !empty(m_curr) && m_curr[1] == '}' && m[1] == '{' + " last was open, current is close, use same indent + return last + elseif !empty(m_curr) && m_curr[1] == '}' && m[1] == '}' + " } line and last line was }: decrease + return last - &sw + endif + if m[1] == '{' + " line after {: increase indent + return last + &sw + else + " line after } or { - same indent + return last + endif + else + return 0 + endif +endfun diff --git a/bundle/vim-haxe/autoload/vaxe/lime.vim b/bundle/vim-haxe/autoload/vaxe/lime.vim new file mode 100644 index 000000000..fb9a3e79f --- /dev/null +++ b/bundle/vim-haxe/autoload/vaxe/lime.vim @@ -0,0 +1,156 @@ +function! vaxe#lime#Targets(...) + return s:lime_targets +endfunction + +function! vaxe#lime#Update(...) + if (a:0 && a:1 != '') + let target = split(a:1)[0] + else + let target = g:vaxe_lime_target + endif + let command = "lime update ".target + call vaxe#Log(command) + call s:Sys(command) +endfunction + +function! vaxe#lime#ProjectLime(...) + if exists('g:vaxe_lime') + unlet g:vaxe_lime + endif + let g:vaxe_working_directory = getcwd() + + if a:0 > 0 && a:1 != '' + let g:vaxe_lime = expand(a:1,':p') + else + let limes = split(glob("**/*.lime"),'\n') + + if len(limes) == 0 + " look for legacy xml files as well... + let limes = split(glob("**/*.xml"),'\n') + if len(limes) == 0 + echoerr "No lime/openfl project files found in current working directory" + return + end + endif + + let base_lime = vaxe#util#InputList("Select Lime", limes) + + if base_lime !~ "^\([a-zA-Z]:\)\=[/\\]" + let base_lime = getcwd() . '/' . base_lime + endif + + echomsg 'Project lime selected: ' . base_lime + + let g:vaxe_lime = base_lime + endif + if !filereadable(g:vaxe_lime) + echoerr "Project lime file not valid, please create one." + return + endif + call vaxe#lime#BuildLimeHxml(g:vaxe_lime) + call vaxe#SetCompiler() + return g:vaxe_lime +endfunction + + +function! vaxe#lime#Clean(...) + if (a:0 && a:1 != '') + let target = split(a:1)[0] + else + let target = g:vaxe_lime_target + endif + let command = "lime clean ".target + call vaxe#Log(command) + call s:Sys(command) +endfunction + +function! vaxe#lime#RebuildHxml() + if exists("b:vaxe_lime") + call vaxe#lime#BuildLimeHxml(b:vaxe_lime) + endif +endfunction + +"A simple system function that first changes directory to the current vaxe +"working directory +function! s:Sys(cmd) + call system("cd ".g:vaxe_working_directory." && ".a:cmd) +endfunction + +function! vaxe#lime#BuildLimeHxml(lime) + let base_hxml = a:lime.".hxml" + + if !strlen(g:vaxe_lime_target) + call vaxe#lime#Target(a:lime) + endif + + let g:vaxe_working_directory = fnamemodify(a:lime, ":p:h") + let cdcmd = 'cd "'.fnameescape(g:vaxe_working_directory).'" && ' + + "create the lime.hxml if not present + if !filereadable(base_hxml) + " pipe lime display to an hxml for completions + let escape_base = fnameescape(base_hxml) + call s:Sys(" echo '# THIS FILE IS AUTOGENERATED BY VAXE, ANY EDITS ARE DISCARDED' " . " > " . escape_base) + call s:Sys(" lime display " . g:vaxe_lime_target + \. " >> " . escape_base ) + endif + + " create the boilerplate code if missing + let simple_target = split(g:vaxe_lime_target)[0] + let output_dir = g:vaxe_working_directory."/Export/".simple_target.'/bin/' + if (!isdirectory(g:vaxe_working_directory."/Export/".simple_target.'/bin')) + " build the assets dependencies + call system(cdcmd . " lime update " . g:vaxe_lime_target) + else + endif + + let b:vaxe_hxml = base_hxml + " let g:vaxe_hxml = b:vaxe_hxml " don't set a global projet var by default +endfunction + +"Sets the target. If target is missing it asks the user. Also updates the +"makeprg compiler command +function! vaxe#lime#Target(lime, ...) + let g:vaxe_lime_target = '' + if a:0 > 1 && a:2 != '' + let g:vaxe_lime_target = a:2 + else + let g:vaxe_lime_target = vaxe#util#InputList("Select Lime Target", s:lime_targets) + let g:vaxe_lime_target = split(g:vaxe_lime_target, ":")[0] + endif + call vaxe#lime#BuildLimeHxml(a:lime) + call vaxe#SetCompiler() +endfunction + + +" A list of all the lime targets +let s:lime_targets = [ "android : Create Google Android applications" + \, "android -arm7 : Compile for arm-7a and arm5" + \, "android -arm7-only : Compile for arm-7a for testing" + \, "blackberry : Create BlackBerry applications" + \, "blackberry -simulator : Build/test for the device simulator" + \, "flash : Create SWF applications for Adobe Flash Player" + \, "html5 : Create HTML5 canvas applications" + \, "html5 -minify : Minify output using the Google Closure compiler" + \, "html5 -minify -yui : Minify output using the YUI compressor" + \, "ios : Create Apple iOS applications" + \, "ios -simulator : Build/test for the device simulator" + \, "ios -simulator -ipad : Build/test for the iPad Simulator" + \, "linux : Create Linux applications" + \, "linux -64 : Compile for 64-bit instead of 32-bit" + \, "linux -neko : Build with Neko instead of C++" + \, "linux -neko -64 : Build with Neko 64-bit instead of C++" + \, "mac : Create Apple Mac OS X applications" + \, "mac -neko : Build with Neko instead of C++" + \, "mac -neko -64 : Build with Neko 64-bit instead of C++" + \, "webos : Create HP webOS applications" + \, "windows : Create Microsoft Windows applications" + \, "windows -neko : Build with Neko instead of C++" + \, "windows -neko -64 : Build with Neko 64-bit instead of C++" ] + + " -D : Specify a define to use when processing other commands + " -debug : Use debug configuration instead of release + " -verbose : Print additional information (when available) + " -clean : Add a "clean" action before running the current command + " (display) -hxml : Print HXML information for the project + " (display) -lime : Print lime information for the project diff --git a/bundle/vim-haxe/autoload/vaxe/util.vim b/bundle/vim-haxe/autoload/vaxe/util.vim new file mode 100644 index 000000000..aa219d49e --- /dev/null +++ b/bundle/vim-haxe/autoload/vaxe/util.vim @@ -0,0 +1,82 @@ +"Vaxe utility functions (vutil) + +" Utility function that recursively searches parent directories for 'dir' +" until a file matching "pattern" is found. +function! vaxe#util#ParentSearch(patterns, dir) + let current_dir = fnamemodify(a:dir,":p:h") + let last_dir = '' + while(current_dir != last_dir) + let last_dir = current_dir + for p in a:patterns + let match = globpath(current_dir, p) + if match != '' + return match + endif + endfor + let current_dir = fnamemodify(current_dir, ":p:h:h") + endwhile + return '' +endfunction + +" returns the current running haxe version on the cache server +function! vaxe#util#HaxeServerVersion() + let response = vaxe#util#SimpleSystem("haxe --connect " + \ . g:vaxe_cache_server_port . ' -version' ) + if response =~ '\v^([0-9]\.)*[0-9]$' + return response + else + return '0' + endif +endfunction + +function! vaxe#util#Strip(str) + return substitute(a:str, '^\s*\(.\{-}\)\s*$', '\1', '') +endfunction + +function! vaxe#util#SimpleSystem(cmd) + let lines = system(a:cmd) + let firstline = split(lines,'\n')[0] + return vaxe#util#Strip(firstline) +endfunction + + +" ye olde default config setter +function! vaxe#util#Config(name, default) + if !exists(a:name) + return a:default + else + return eval(a:name) + endif +endfunction + + +" Utility function that lets users select from a list. If list is length 1, +" then that item is returned. Uses tlib#inpu#List if available. +function! vaxe#util#InputList(label, items) + if len(a:items) == 1 + return a:items[0] + endif + if exists("g:loaded_tlib") + return tlib#input#List("s", a:label, a:items) + else + let items_list = map(range(len(a:items)),'(v:val+1)." ".a:items[v:val]') + let items_list = [a:label] + items_list + let sel = inputlist(items_list) + " 0 is the label. If that is returned, just use the first item in the + " list instead + if sel == 0 + let sel = 1 + endif + return a:items[sel-1] + endif +endfunction + +" Utility function that returns a list of unique values in the list argument. +function! vaxe#util#UniqueList(items) + let d = {} + for v in a:items + let d[v] = 1 + endfor + return keys(d) +endfunction + diff --git a/bundle/vim-haxe/compiler/haxe.vim b/bundle/vim-haxe/compiler/haxe.vim new file mode 100644 index 000000000..be5bbda34 --- /dev/null +++ b/bundle/vim-haxe/compiler/haxe.vim @@ -0,0 +1,13 @@ +" Vim compiler file +" Compiler: haxe +" Maintainer: Justin Donaldson + + + +" select a build file if none is available +" this function sets the makeprg and errorformat +if !exists("b:vaxe_hxml") + call vaxe#AutomaticHxml() +endif + + diff --git a/bundle/vim-haxe/doc/vaxe.txt b/bundle/vim-haxe/doc/vaxe.txt new file mode 100644 index 000000000..bde3f9014 --- /dev/null +++ b/bundle/vim-haxe/doc/vaxe.txt @@ -0,0 +1,500 @@ +*vaxe.txt* A plugin for working with the Haxe language. For Vim version 7.3 + +============================================================================== +Author: Justin Donaldson *vaxe-author* +License: WTFPL (see |vaxe-license|) +============================================================================== +CONTENTS *vaxe-contents* + +|vaxe-introduction| Introduction and Feature Summary +|vaxe-commands| Commands +|vaxe-functions| Functions +|vaxe-settings| Settings +|compiler-vaxe| Compiler + +{Incompatible with Vi} + +============================================================================== + +INTRODUCTION *vaxe* + *vaxe-introduction* + +This plugin adds basic support for Haxe syntax, indenting, and compiling. In +addition, it provides functions and features for advanced vim features such as +|omnifunc|, |makeprg|, and |ctags|, as well as supporting useful bundles such +as |tagbar|, |neocomplcache|, |snipmate|, and |powerline|. Also included is +syntax and support for Hxml. + +Vaxe uses the Haxe compiler extensively to determine code completions, and +generate various metadata. The compiler, in turn, uses sequences of compiler +directives in "hxml" files in order to specify build and output options, +similar to gnu makefiles. To trigger completions manually, use CTRL-X CTRL-O +after the period following a field or module. This will trigger the |omnifunc|. + +Vaxe has two different "build modes" that designate how to find the hxml +file, as well as how to set up the |makeprg|. If you're working with simple +projects, then the default mode will work just fine. If you have a complex +project structure with many different sub-builds, then you may want to consider +using |vaxe-project-mode|. You can set up an autocommand to set the project +hxml: + +> +:autocmd BufNewFile,BufRead /project/* vaxe#ProjectHxml("/project/project.hxml") +< + +Keep in mind that the project mode will persist throughout your entire session. +If you wish to exit project mode, use the DefaultHxml command, or +vaxe#DefaultHxml function. Also, the quickfix list and related compiler +information will always be in relation to the working directory at compilation +time. It is a good idea to keep an hxml file in the root of your working +directory, and use vaxe to invoke the compiler there. + +If you need to change the name of the hxml file often, it may be a good idea +to print the name of the build file in your statusline, to remind you which +file is being used for "make" and completions: + +> +:autocmd BufNewFile,BufRead *.hx set statusline+=\ build:\ %{vaxe#CurrentBuild()} +< + +============================================================================== +BUILD MODES *vaxe-build* + +Default *vaxe-default-mode* + This mode is used automatically any time a *.hx file + is opened. It can be retriggered by calling + |vaxe#DefaultHxml|. Vaxe will search the project + path for the preferred file indicated by + |g:vaxe_default_parent_search_glob|. + + If it finds a preferred build file in the parent + directories of the currently edited file, it will set + a b:vaxe_hxml variable for the current buffer. + It sets a |makeprg| that has the following behavior: + It will cd to the discovered hxml directory, call the + compiler with the hxml, and redirect errors to + standard out. + +Project *vaxe-project-mode* + This mode is used when |vaxe#ProjectHxml| is called. + It will set a g:vaxe_hxml variable that will + override any b:vaxe_hxml variables set by the default + method. It also sets a |makeprg| that simply executes + the haxe compiler in the working directory, + and redirects errors to standard out. Project mode + assumes that you will keep the same working directory + throughout your vim session. + + +Lime Project *vaxe-lime-mode* + This mode is used when |vaxe#lime#ProjectLime| is + called, or if an lime file is detected on startup. it + will set a g:vaxe_lime variable that will override any + b:vaxe_lime variables set by the default method. it + also sets a |makeprg| that simply executes the lime + command in the working directory, and redirects errors + to standard out. Lime mode assumes that you will keep + the same working directory throughout your vim session. + when this mode is active, an hxml file is generated + that contains information used for completions. it + will be named the same as the selectd lime file, and be + located in the same directory, but will have an hxml + extension. + +Flow Project *vaxe-flow-mode* + This mode is used when |vaxe#flow#ProjectFlow| is + called, or if an flow file is detected on startup. it + will set a g:vaxe_flow variable that will override any + b:vaxe_flow variables set by the default method. it + also sets a |makeprg| that simply executes the flow + command in the working directory, and redirects errors + to standard out. Flow mode assumes that you will keep + the same working directory throughout your vim session. + when this mode is active, an hxml file is generated + that contains information used for completions. it + will be named the same as the selectd flow file, and be + located in the same directory, but will have an hxml + extension. + +============================================================================== + +COMPILATION CACHE SERVER SUPPORT *vaxe-cache-server* + +Set |g:vaxe_cache_server| to 1 in order to enable a cache server for +compilation. The haxe compiler will cache unchanged modules, which will +greatly speed up the compilation of larger projects. It is currently only +supported on unix/darwin targets. + +Currently, it only supports unix-based systems, and is only used during +compiler-based completion requests (not for builds). + +The server will be killed upon exiting vim. You can also kill it with +|KillHaxeCompletionServer|, and start it again with |StartHaxeCompletionServer|. + +============================================================================== + +HAXE COMMANDS *vaxe-commands* + +|DefaultHXML| Call the |vaxe#DefaultHxml| function. Accepts an + optional single argument that will specify the hxml, + lime or flow project file to use. + +|ProjectHXML| Call the |vaxe#ProjectHxml| function. Accepts an + optional single argument that will specify the hxml to + use. + + use. + +|VaxeCtags| Call the |vaxe#Ctags| function + +|VaxeToggleLogging| Turns vaxe logging on/off (logs to :message) + + +|VaxeStartCompletionServer| + Starts the Haxe completion server + +|VaxeStopCompletionServer| + Stops the Haxe completion server + +============================================================================== + +LIME COMMANDS *vaxe-lime-commands* +There's a number of lime-specific commands that closely match the command +line counterparts. LimeTarget,Clean,Update all accept an optional target +argument. The argument can be tab-completed. If a target is not specified +with LimeTarget, one will be chosen from an input list. + +|ProjectLime| Call the |vaxe#ProjectLime| function. Accepts an + optional single argument that will specify the lime to + use + +|LimeTarget| Call the |vaxe#lime#Target| function. + +|LimeClean| Call the |vaxe#lime#Clean| function. + +|LimeUpdate| Call the |vaxe#lime#Update| function. + +|LimeRebuildHxml| Call the |vaxe#lime#RebuildHxml| function. + +============================================================================== + +FLOW COMMANDS *vaxe-flow-commands* +There's a number of flow-specific commands that closely match the command +line counterparts. FlowTarget,Clean all accept an optional target +argument. The argument can be tab-completed. If a target is not specified +with FlowTarget, one will be chosen from an input list. + +|ProjectFlow| Call the |vaxe#ProjectFlow| function. Accepts an + optional single argument that will specify the flow to + use + +|FlowTarget| Call the |vaxe#flow#Target| function. + +|FlowClean| Call the |vaxe#flow#Clean| function. + +|FlowRebuildHxml| Call the |vaxe#flow#RebuildHxml| function. + +============================================================================== + +VAXE COMPLETION SERVER COMMANDS *vaxe-completion-server-commands* +These are commands for starting and stopping the completion server. If you +wish to set defaults for the completion server, check |cache server settings|. + +|VaxeStartServer| Starts the completion server +|VaxeStopServer| Stops the completion server + +============================================================================== + +FUNCTIONS *vaxe-functions* + +*vaxe#CompilerClassPaths* + Retrieve the class paths for the current build target. + +*vaxe#Ctags* Generate a ctags file for the current build target. + This function will use the compiler class paths for the + current build, which will include all standard + libraries, as well as libraries from included haxelibs. + vaxe also provides a tag description file that can + be used with |tagbar| if it is installed. + +*vaxe#CurrentBuild* Returns the current active project build file if it + is specified, else it will return the default build + file name if it exists. Accepts a single argument that + will specify the hxml to use. + + +*vaxe#DefaultHxml* Find the preferred build file recursively in the + parents of the working directory. This function is + called automatically whenever any hx file is opened. + Accepts a single optional argument that will specify + the hxml (or lime/flow project) to use. + +*vaxe#HaxeComplete* The |omnifunc| provided for vaxe. + +*vaxe#OpenHxml* Open the current build file specified with + |vaxe#DefaultHxml|, or |vaxe#ProjectHxml|. You can + easily add this function to a trigger: + > + map oh :call vaxe#OpenHxml() + < + +*vaxe#ProjectHxml* Find and select hxml files in the working directory. + Selecting a file with this method will enter + |vaxe-project-mode|. If you have installed |tlib|, + then it will use |tlib#input#List| to select hxml + candidates. If you call this often, it makes sense to + map it to a leader action: + > + map ph : call vaxe#ProjectHxml() + < + + +*vaxe#ImportClass* Calling this function on a given line will try to + import any classes that are given for the line. E.g. + for this line: + > + var l = new haxe.FastList(); + < + vaxe#ImportClass() will try to find the FastList + definition, and import it: + > + import haxe.FastList; + ... + var l = new FastList(); + < + If you're missing the initial package prefix, vaxe + will try to find package definitions for the given + class name using ctags. So, if ctags are generated, + it is also possible to resolve the import for this + line: + > + var l = new FastList(); + > + + +*vaxe#lime#Target* Calling this function will select a new lime target to + use for builds and completions. + +*vaxe#lime#Targets* Calling this function will return a list of all lime + targets supported by vaxe. + +*vaxe#lime#Update* Calling this function will update the boilerplate code + for the current target, or the target specified by the + (optional) argument. + +*vaxe#lime#Clean* Calling this function will clean the boilerplate code + for the current target, or the target specified by the + (optional) argument. + +*vaxe#lime#RebuildHxml* Calling this function rebuilds the associated hxml + used for completions, etc. + +*vaxe#flow#Target* Calling this function will select a new flow target to + use for builds and completions. + +*vaxe#flow#Targets* Calling this function will return a list of all flow + targets supported by vaxe. + +*vaxe#flow#Clean* Calling this function will clean the boilerplate code + for the current target, or the target specified by the + (optional) argument. + +*vaxe#flow#RebuildHxml* Calling this function rebuilds the associated hxml + used for completions, etc. + +============================================================================== + +ACTIVE TARGET *omnifunc-active-target* + +In some cases, an hxml file may specify multiple targets via a "--next" +directive. The specified behavior for the compiler may be very different +betwen --next sections. + +vaxe will use the first section it finds in order to generate completions. +It is possible to specify a different target by inserting a line like this into +your hxml: +> + # display completions +< +The target that vaxe uses is called the "active" target. This target is used +for generating completions, as well as for determining current compiler class +paths, and for generating ctags. + +============================================================================== + +SETTINGS *vaxe-settings* + + +*g:vaxe_prefer_hxml* The name of the hxml file/glob to search for and use + automatically. The default is "build.hxml". + +*g:vaxe_prefer_lime* The name of the lime file/glob to search for and use + automatically. The default is "*.lime". + +*g:vaxe_prefer_flow* The name of the flow file/glob to search for and use + automatically. The default is "*.flow". + +*g:vaxe_prefer_openfl* The name of the openfl file/glob to search for and use + automatically. The default is "project.xml". + NOTE: this is a legacy file type that lime can still + handle, it is recommended to use a *.lime file where + possible. + +*g:vaxe_prefer_first_in_directory* + When vaxe finds more than one build file in a directory, + setting this variable to 1 will make vaxe always choose + the first one. If it is set to 0, then it will present + a list of options. The default is 1. + +*g:vaxe_lime_target* If you commonly work with a single target, this option + allows you to set a default target for lime to use when + compiling. + +*g:vaxe_flow_target* If you commonly work with a single target, this option + allows you to set a default target for flow to use when + compiling. + +*g:vaxe_default_parent_search_patterns* + This is a list of |glob| patterns that vaxe uses to + determine which hxml (or lime/flow) file to use on startup. + The default is: + > + [g:vaxe_prefer_lime, g:vaxe_prefer_flow, g:vaxe_prefer_hxml, '*.hxml'] + < + + Note that vaxe will search recursively through + each parent directory, and stop at the first file that + matches the pattern. E.g., by default, vaxe will + recursively look for *any* lime file, or one called + 'build.hxml'. It will give precedence to the lime file, + since it occurs before the hxml file in the search + pattern list. Finally, if none of those options are + available, it will fall back to using any hxml file + it can find. + +*g:vaxe_hxml* A variable that indicates the |vaxe-project-mode| + build file. It will override the |vaxe-default-mode| + setting if present. + +*g:vaxe_skip_hxml* Setting this variable will skip checks for a valid hxml + file. Use this if you wish to use an alternative build + system and are willing to forgo completion support. + +*g:vaxe_completion_alter_signature* + Changes the method signatures in autocompletions to a + syntax form, instead of a type signature. This is + enabled by default +> + # type signature: + some_method [f] arg1 : Int -> arg2 : String -> Bool + # syntax form: + some_method [f] (arg1 : Int, arg2 : String) : Bool +< + +*g:vaxe_completion_write_compiler_ouput* + Determines whether or not vaxe should let the compiler + write the output generated from a completion request. + Defaults to 0 (equivalent to always adding --no-output + in the hxml). + +*g:vaxe_completion_prevent_bufwrite_events* + Vaxe uses the compiler to make completions. This can + happen frequently, and causes the buffer to be written. + This can in turn interfere with other scripts that + handle bufwrite events, triggering them excessively. + The default is "1" which prevents events that happen + as the result of completion activity. + +*g:vaxe_completeopt_menuone* + It's nice if Vaxe can use "simple" completions for + haxe, since these can be used for contextual info + messages. The default here is to add "menuone" + to the list of completeopts. However, this option + is global, so it may cause a conflict. If this + causes a problem then set this variable to 0. + + +*g:vaxe_cache_server* *cache server settings* + Vaxe will enable the usage of a haxe compilation cache + server, which currently is used only for completions, + and defaults to 0. + +*g:vaxe_cache_server_port* + The port that the cache server will use (defaults to + 6878) + +*g:vaxe_cache_server_autostart* + Whether the server should be autostarted with vim + (defaults to 1). + +*g:vaxe_completion_require_autowrite* + This setting requires autowrite to be enabled for + completions. It defaults to 1. If |autowrite| or + |autowriteall| is not set, then Vaxe will display an + error message instead of any completion results. If + set to 0, the completion will be tried normally, and + the user will be expected to save each time before + triggering a completion. + +*g:vaxe_completion_disable_optimizations* + This setting adds "-D no-copt" to hxml, which will + disable certain optimizations the haxe compiler uses + to determine completions. There's still a few cases + where optimization causes problems, so optimizations are + disabled by default. + +*g:vaxe_trace_absolute_path* + This setting adds "-D absolute_path" to hxml, which + will enable the output of absolute path in trace + messages, etc. This enables the quickfix list to jump + to files more easily, so by default, this is 1. + + *third party settings* +*g:vaxe_enable_airline_defaults* + Vaxe provides support for vim-airline by changing the + filename display to also include the current hxml build + file (defaults to 1). + +*g:vaxe_enable_ycm_defaults* + Vaxe provides support for YouCompleteMe by providing a + filetype and completion trigger character configuration + (defaults to 1). Note: It is recommended to use only + one autocompletion plugin. + +*g:vaxe_enable_acp_defaults* + Vaxe provides support for AutoComplPop by providing a + filetype and completion trigger character configuration + (defaults to 1). Note: It is recommended to use only + one autocompletion plugin. + +============================================================================= + +MISC *vaxe-misc* + +Vaxe will change the errrorformat syntax if it finds "-D absolute_path" in the +current hxml. This -D compiler switch adds the full path for files in trace +output, making it possible to jump to trace declarations in the quickfix +window. + + +LICENSE *vaxe-license* + +Copyright (C) 2012 Justin Donaldson + +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. diff --git a/bundle/vim-haxe/ftdetect/flow.vim b/bundle/vim-haxe/ftdetect/flow.vim new file mode 100644 index 000000000..3e5898360 --- /dev/null +++ b/bundle/vim-haxe/ftdetect/flow.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.flow set filetype=flow.javascript diff --git a/bundle/vim-haxe/ftdetect/haxe.vim b/bundle/vim-haxe/ftdetect/haxe.vim new file mode 100644 index 000000000..e148c6c5e --- /dev/null +++ b/bundle/vim-haxe/ftdetect/haxe.vim @@ -0,0 +1,2 @@ +autocmd BufNewFile,BufRead *.hx set filetype=haxe + diff --git a/bundle/vim-haxe/ftdetect/hss.vim b/bundle/vim-haxe/ftdetect/hss.vim new file mode 100644 index 000000000..46d253605 --- /dev/null +++ b/bundle/vim-haxe/ftdetect/hss.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.hss set filetype=hss diff --git a/bundle/vim-haxe/ftdetect/hxml.vim b/bundle/vim-haxe/ftdetect/hxml.vim new file mode 100644 index 000000000..c5450b59b --- /dev/null +++ b/bundle/vim-haxe/ftdetect/hxml.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.hxml set filetype=hxml diff --git a/bundle/vim-haxe/ftdetect/lime.vim b/bundle/vim-haxe/ftdetect/lime.vim new file mode 100644 index 000000000..b174624fc --- /dev/null +++ b/bundle/vim-haxe/ftdetect/lime.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.lime set filetype=lime.xml diff --git a/bundle/vim-haxe/ftdetect/nmml.vim b/bundle/vim-haxe/ftdetect/nmml.vim new file mode 100644 index 000000000..265130f16 --- /dev/null +++ b/bundle/vim-haxe/ftdetect/nmml.vim @@ -0,0 +1 @@ +autocmd BufNewFile,BufRead *.nmml set filetype=nmml.xml diff --git a/bundle/vim-haxe/ftplugin/haxe.vim b/bundle/vim-haxe/ftplugin/haxe.vim new file mode 100644 index 000000000..d5309f76f --- /dev/null +++ b/bundle/vim-haxe/ftplugin/haxe.vim @@ -0,0 +1,47 @@ +compiler haxe +setlocal omnifunc=vaxe#HaxeComplete + + + +let run_once = 0 + +if (!run_once) + " Start a server the first time a hx file is edited + if g:vaxe_cache_server && ! exists('g:vaxe_cache_server_pid') + call vaxe#StartCacheServer() + endif + + " Utility variable that stores the directory that this script resides in + "Load the first time a haxe file is opened + let s:plugin_path = escape(expand(':p:h') . '/../python/', '\') + if has("python3") + exe 'py3file '.s:plugin_path.'/vaxe.py' + elseif has("python") + exe 'pyfile '.s:plugin_path.'/vaxe.py' + endif + + " load special configuration for vim-airline if it exists + if (exists("g:loaded_airline") && g:vaxe_enable_airline_defaults ) + function! AirlineBuild(...) + if &filetype == 'haxe' + let w:airline_section_c = + \ '%{VaxeAirlineProject()}' + \. ' %{pathshorten(fnamemodify(vaxe#CurrentBuild(), ":."))}' + \. ' [%{vaxe#CurrentBuildPlatform()}] ' + \. g:airline_left_alt_sep + \. ' %f%m' + endif + endfunction + call add(g:airline_statusline_funcrefs, function('AirlineBuild')) + endif +endif + +function! VaxeAirlineProject() + return exists("g:vaxe_hxml") ? '★ ' : '☆ ' +endfunction + +" we need to show single entry completions for haxe, because I use those for +" info messages on occasion +if (g:vaxe_completeopt_menuone) + setlocal completeopt+=menuone +endif diff --git a/bundle/vim-haxe/ftplugin/hss.vim b/bundle/vim-haxe/ftplugin/hss.vim new file mode 100644 index 000000000..97dd1830e --- /dev/null +++ b/bundle/vim-haxe/ftplugin/hss.vim @@ -0,0 +1 @@ +setlocal indentexpr=vaxe#hss#GetIndent(v:lnum) diff --git a/bundle/vim-haxe/ftplugin/hxml.vim b/bundle/vim-haxe/ftplugin/hxml.vim new file mode 100644 index 000000000..9d28a6dfd --- /dev/null +++ b/bundle/vim-haxe/ftplugin/hxml.vim @@ -0,0 +1 @@ +call vaxe#DefaultHxml(expand("%")) diff --git a/bundle/vim-haxe/indent/haxe.vim b/bundle/vim-haxe/indent/haxe.vim new file mode 100644 index 000000000..903743fc2 --- /dev/null +++ b/bundle/vim-haxe/indent/haxe.vim @@ -0,0 +1,15 @@ +" Language: Haxe +" Maintainer: None! Wanna improve this? +" Last Change: 2007 Jan 22 + +" Only load this indent file when no other was loaded. +if exists("b:did_indent") + finish +endif +let b:did_indent = 1 + +" C indenting is not too bad. +setlocal cindent +setlocal cinoptions+=j1,J1 +setlocal indentkeys=0{,0},0),0],!^F,o,O,e +let b:undo_indent = "setl cin<" diff --git a/bundle/vim-haxe/plugin/haxe.vim b/bundle/vim-haxe/plugin/haxe.vim new file mode 100644 index 000000000..3adac3b02 --- /dev/null +++ b/bundle/vim-haxe/plugin/haxe.vim @@ -0,0 +1,156 @@ +if exists("g:loaded_vaxe_plugin") + finish +endif + +let g:loaded_vaxe_plugin = 1 + +if has("python3") + let g:vaxepy = ":python3 " +elseif has("python") + let g:vaxepy = ":python " +endif + +command -nargs=? -complete=file DefaultHxml call vaxe#DefaultHxml() +command -nargs=? -complete=file ProjectHxml call vaxe#ProjectHxml() +command VaxeToggleLogging let g:vaxe_logging = !g:vaxe_logging + +" Lime commands +command -nargs=? -complete=file ProjectLime + \ call vaxe#lime#ProjectLime() + +command -nargs=? -complete=customlist,vaxe#lime#Targets LimeTarget + \ call vaxe#lime#Target() + +command -nargs=? LimeClean + \ call vaxe#lime#Clean() + +command -nargs=? LimeUpdate + \ call vaxe#lime#Update() + +command -nargs=? LimeRebuildHxml + \ call vaxe#lime#RebuildHxml() + + +" Flow commands +command -nargs=? -complete=file ProjectFlow + \ call vaxe#flow#ProjectFlow() + +command -nargs=? -complete=customlist,vaxe#flow#Targets FlowTarget + \ call vaxe#flow#Target() + +command -nargs=? FlowClean + \ call vaxe#flow#Clean() + +command -nargs=? FlowRebuildHxml + \ call vaxe#flow#RebuildHxml() + +" Completion Server Commands +command VaxeStopCompletionServer call vaxe#KillCacheServer() +command VaxeStartCompletionServer call vaxe#StartCacheServer() + +command VaxeCtags call vaxe#Ctags() + +autocmd FileType haxe setlocal commentstring=//%s + +let g:tagbar_type_haxe = { + \ 'ctagstype' : 'haxe', + \ 'kinds' : [ + \ 'a:abstracts', + \ 'c:classes', + \ 'e:enums', + \ 'i:interfaces', + \ 't:typedefs', + \ 'v:variables', + \ 'f:functions', + \ ] + \ } + +" a short alias, since I use this all over the place +let Default = function("vaxe#util#Config") + +" misc options +let g:vaxe_haxe_version = Default('g:vaxe_haxe_version', 3) +let g:vaxe_logging = Default('g:vaxe_logging', 0) +let g:vaxe_trace_absolute_path = Default('g:vaxe_trace_absolute_path', 1) + +" completion options +let g:vaxe_completion_require_autowrite + \=Default('g:vaxe_completion_require_autowrite', 1) +let g:vaxe_completion_disable_optimizations + \= Default('g:vaxe_completion_disable_optimizations', 1) +let g:vaxe_completion_alter_signature + \= Default('g:vaxe_completion_alter_signature', 1) +let g:vaxe_completion_collapse_overload + \= Default('g:vaxe_completion_collapse_overload', 0) +let g:vaxe_completion_write_compiler_output + \= Default('g:vaxe_completion_write_compiler_output', 0) +let g:vaxe_completion_prevent_bufwrite_events + \= Default('g:vaxe_completion_prevent_bufwrite_events',1) +let g:vaxe_completeopt_menuone + \= Default('g:vaxe_completeopt_menuone', 1) + +" cache server options +let g:vaxe_cache_server = Default('g:vaxe_cache_server', 0) +let g:vaxe_cache_server_port = Default('g:vaxe_cache_server_port', 6878) +let g:vaxe_cache_server_autostart = Default('g:vaxe_cache_server_autostart', 1) + +" lime options +let g:vaxe_lime_test_on_build = Default('g:vaxe_lime_test_on_build', 1) +let g:vaxe_lime_target = Default('g:vaxe_lime_target',"") +let g:vaxe_lime_completion_target = Default('g:vaxe_lime_completion_target', 'flash') + +" flow options +let g:vaxe_flow_target = Default('g:vaxe_flow_target', "") +let g:vaxe_flow_completion_target = Default('g:vaxe_flow_completion_target', 'web') + +" default build options +let g:vaxe_prefer_hxml = Default('g:vaxe_prefer_hxml', "build.hxml") +let g:vaxe_prefer_lime = Default('g:vaxe_prefer_lime', "*.lime") +let g:vaxe_prefer_flow = Default('g:vaxe_prefer_flow', "*.flow") +let g:vaxe_prefer_openfl = Default('g:vaxe_prefer_openfl', "project.xml") +let g:vaxe_prefer_first_in_directory = Default('g:vaxe_prefer_first_in_directory', 1) +let g:vaxe_default_parent_search_patterns + \= Default('g:vaxe_default_parent_search_patterns' + \, [g:vaxe_prefer_lime, g:vaxe_prefer_flow, g:vaxe_prefer_openfl, g:vaxe_prefer_hxml, "*.hxml"]) +let g:vaxe_set_makeprg = Default('g:vaxe_set_makeprg', 1) + +" Supported 3rd party plugin options +let g:vaxe_enable_airline_defaults = Default('g:vaxe_enable_airline_defaults', 1) +let g:vaxe_enable_ycm_defaults = Default('g:vaxe_enable_ycm_defaults', 1) +let g:vaxe_enable_acp_defaults = Default('g:vaxe_enable_acp_defaults', 1) + +if !exists('g:vaxe_haxe_binary') + let g:vaxe_haxe_binary = 'haxe' +endif + +" YCM +if (g:vaxe_enable_ycm_defaults) + if ( exists("g:ycm_semantic_triggers") ) + let g:ycm_semantic_triggers['haxe'] = ['.', '('] + else + let g:ycm_semantic_triggers = { 'haxe' : ['.', '('] } + endif +endif + +" ACP +if (g:vaxe_enable_acp_defaults) + if !exists('g:acp_behavior') + let g:acp_behavior = {} + endif + + function! haxe#meetsForFile(context) + return a:context =~ '\(\.\|(\)$' + endfunction + if !has_key(g:acp_behavior, 'haxe') + let g:acp_behavior['haxe'] = [] + endif + + let vaxe_entry = { + \ "meets" : "haxe#meetsForFile", + \ "command": "\\", + \ "completefunc" : "vaxe#HaxeComplete"} + + call add(g:acp_behavior['haxe'] , vaxe_entry) +endif + + diff --git a/bundle/vim-haxe/plugin/hxml.vim b/bundle/vim-haxe/plugin/hxml.vim new file mode 100644 index 000000000..4fc6cb1e9 --- /dev/null +++ b/bundle/vim-haxe/plugin/hxml.vim @@ -0,0 +1,2 @@ +autocmd FileType hxml setlocal commentstring=#%s + diff --git a/bundle/vim-haxe/python/vaxe.py b/bundle/vim-haxe/python/vaxe.py new file mode 100644 index 000000000..94fc95dc0 --- /dev/null +++ b/bundle/vim-haxe/python/vaxe.py @@ -0,0 +1,166 @@ +import vim, re +import string + +try: + import HTMLParser +except: + from html.parser import HTMLParser + +import xml.etree.ElementTree as ET +import json + + + +# This is the python portion of the completion script. Call it with the *name* +# of the input vimscript variable, "complete_output_var". This should contain +# the output from the --display compiler directive. base_var is an optional +# partial word to use for filtering completions. +# The output is given in "output_var", which is likewise the name of the +# vimscript variable to write. This variable contains a dictionary formatted +# appropriately for an omnifunc. "base_var" contains an optional partial word +# to filter for +def complete(complete_output_var, output_var, base_var , alter_var, collapse_var): + complete_output = vim.eval(complete_output_var) + base = vim.eval(base_var) + alter_sig = vim.eval(alter_var) != '0' + collapse_overload = vim.eval(collapse_var) != '0' + if complete_output is None: complete_output = '' + completes = [] + + # get rid of non-printable characters that would be + # in the embedded doc (e.g. ANSI escape characters) + # thus preventing ET.XML to work + complete_output = re.sub(f'[^{re.escape(string.printable)}]', '', complete_output ) + + # wrap in a tag to prevent parsing errors + root = ET.XML("" + complete_output + "") + + fields = root.findall("list/i") + types = root.findall("type") + completes = [] + + if len(fields) > 0: # field completion + def fieldxml2completion(x): + word = x.attrib["n"] + menu = x.find("t").text + info = x.find("d").text + menu = '' if menu is None else menu + if info is None: + info = [''] + else: + # get rid of leading/trailing ws/nl + info = info.strip() + # strip html + info = remove_html_markup(info) + # split and collapse extra whitespace + info = [re.sub(r'\s+',' ',s.strip()) for s in info.split('\n')] + + abbr = word + kind = 'v' + if menu == '': kind = 'm' + elif re.search("\->", menu): + kind = 'f' # if it has a -> + if alter_sig: + menu = alter_signature(menu) + word += "(" + + return { 'word': word, 'info': info, 'kind': kind + ,'menu': menu, 'abbr': abbr, 'dup':1 } + + completes = [fieldxml2completion(f) for f in fields] + elif len(types) > 0: # function type completion + otype = types[0].text.strip() + h = HTMLParser.HTMLParser() + word = ' ' + info = [h.unescape(otype)] + abbr = info[0] + if otype == "Dynamic": + completes = [{'word': word,'info':info + , 'abbr': "Dynamic (Will likely cause compiler error.)" + , 'dup':1} + ] + elif alter_sig: + abbr = alter_signature(abbr) + completes= [{'word': word,'info':info, 'abbr':abbr, 'dup':1}] + + if base != '' and base is not None: + completes = [c for c in completes if re.search("^" + base, c['word'])] + + if collapse_overload: + dict_complete = dict() + def complete_exists(c): + if c in dict_complete: + dict_complete[c] += 1 + return True + else: + dict_complete[c] = 1 + return False + completes = [c for c in completes if not complete_exists(c['abbr'])] + for c in completes: + if dict_complete[c['abbr']] > 1: + c['menu'] = "@:overload " + c['menu'] + vim.command("let " + output_var + " = " + json.dumps(completes)) + +# simple script to grab lists of locations from display-mode completions +def locations(complete_output_var, output_var): + complete_output = vim.eval(complete_output_var) + # wrap in a tag to prevent parsing errors + root = ET.XML("" + complete_output + "") + pos = root.findall("pos") + completes = [] + if len(pos) > 0: + completes = [p.text for p in pos] + else: + completes = [] + vim.command("let " + output_var + " = " + json.dumps(completes)) + +def alter_signature(sig): + paren = 0 + last_string = '' + final_expr = '' + for i in range(len(sig)): + c = sig[i] + if c == "(": + paren += 1 + final_expr += re.sub('->',",", last_string) + last_string = c + elif c == ")": + last_string += c + paren -=1 + if paren == 0: + final_expr += last_string + last_string = '' + else: + last_string += c + + final_expr = final_expr + re.sub('\s*->\s*', ",", last_string) + parts = final_expr.split(',') + ret_val = parts.pop() + if ret_val == "Void": + ret_val = '' + else: + ret_val = " : " + ret_val + + if len(parts) ==1 and parts[0] == "Void": + parts[0] = '' + + final_expr = '(' + ", ".join(parts) + ')' + ret_val + return final_expr + +# simple script to strip html markup +def remove_html_markup(s): + tag = False + quote = False + out = "" + + for c in s: + if c == '<' and not quote: + tag = True + elif c == '>' and not quote: + tag = False + elif (c == '"' or c == "'") and tag: + quote = not quote + elif not tag: + out = out + c + + return out diff --git a/bundle/vim-haxe/snippets/haxe.snippets b/bundle/vim-haxe/snippets/haxe.snippets new file mode 100644 index 000000000..bec562b02 --- /dev/null +++ b/bundle/vim-haxe/snippets/haxe.snippets @@ -0,0 +1,94 @@ +# Vim snippets file +# Author : Justin Donaldson (jdonaldson@gmail.com) +# Based extensively on a version by Marc Weber (marco-oweber@gmx.de) +# Language : haxe + +#javadoc +snippet doc + /** + ${1} + **/ +snippet switch + switch(${1}){ + case ${2}: ${3} + } +snippet case + case ${1}: ${2} +snippet try + try{ + ${1} + }catch(e:${2}){ + ${3:// Ignore any errors.} + } +snippet for + for( ${1:var} in ${2:itr} ){ + ${3} + } +snippet class HAXE + class `expand('%:t:r')` { + + public function new(${1}) { + ${2://initialize variables} + } + + static function main() { + ${3:trace("hello world");} + } + + } +snippet main + static function main() { + ${1:trace("hello world");} + } +snippet new + public function new(${1:arg}) { + super($1); + } +snippet fn func + function(${1:arg}) { + ${2} + } +snippet fu function + function ${1:name}(${2:arg}) { + ${3} + } +snippet prifu private function + private function ${1:name}(${2:arg}) { + ${3} + } +snippet pufu public function + public function ${1:name}(${2:arg}) { + ${3} + } +snippet pustafu public static function + public static function ${1:name}(${2:arg}) { + ${3} + } +snippet pristafu private static function + private static function ${1:name}(${2:arg}) { + ${3} + } +snippet trace + trace(${1}); +snippet desc function + trace(${1} + " is the value for $1"); +snippet cast + cast(${1:cast_this}, ${2:type}) +snippet interface + interface ${1:name}${2: implements this}${3:, implements other}{ + ${4} + } +snippet #if + #if js, php, cpp, flash + ${1} + #end{2} +snippet typedef + typedef ${1}${2:} = { + var ${3}:$2; + }${4} +snippet untyped + untyped{ ${1} }${2} +snippet enum + enum ${1:Name} { + ${2:Construct} + } diff --git a/bundle/vim-haxe/snippets/hxml.snippets b/bundle/vim-haxe/snippets/hxml.snippets new file mode 100644 index 000000000..c124050a1 --- /dev/null +++ b/bundle/vim-haxe/snippets/hxml.snippets @@ -0,0 +1,51 @@ +# Vim snippets file +# Author : Justin Donaldson (jdonaldson@gmail.com) +# Based extensively on a version by Marc Weber (marco-oweber@gmx.de) +# Language : hxml + +snippet resource + -resource ${1:file}${2:@name(optional)} +snippet neko + -main ${1:Main} + -neko ${2:bin/}$1.n +snippet flash9 + -main ${1:Main} + -swf9 ${2:bin/}$1.v9.swf +snippet flash + -main ${1:Main} + -swf ${2:bin/}$1.swf +snippet php + -main ${1:Main} + -php php +snippet js + -main ${1:Main} + -js $2$1.js +snippet cpp + -main ${1:Main} + -cpp cpp +snippet remap + --remap ${1:neko}:$2 +snippet all + -main ${1:Main} + -neko ${2:bin/}$1.n + ${3:} + --next + -main $1 + -swf9 $2$1.v9.swf + $3 + --next + -main $1 + -swf $2$1.v8.swf + $3 + --next + -main $1 + -php php + $3 + --next + -main $1 + -js $2$1.js + $3 + --next + -main $1 + -cpp cpp + $3 diff --git a/bundle/vim-haxe/snippets/nmml.snippets b/bundle/vim-haxe/snippets/nmml.snippets new file mode 100644 index 000000000..cee78528e --- /dev/null +++ b/bundle/vim-haxe/snippets/nmml.snippets @@ -0,0 +1,29 @@ +snippet meta + +snippet app + +snippet assets + +snippet graphics + +snippet audio + + +snippet font + +snippet source + +snippet lib + +snippet fps + +snippet fullscren + +snippet window + +snippet haxeflag + +snippet ndll + +snippet icon + diff --git a/bundle/vim-haxe/syntax/README.md b/bundle/vim-haxe/syntax/README.md new file mode 100644 index 000000000..9930a4894 --- /dev/null +++ b/bundle/vim-haxe/syntax/README.md @@ -0,0 +1,5 @@ +There are a few vim plugins for Haxe: +1) [vaxe](https://github.com/jdonaldson/vaxe) +2) [vim-haxe](https://github.com/MarcWeber/vim-haxe) + +This syntax file serves as a common form for syntax highlighting. diff --git a/bundle/vim-haxe/syntax/haxe.vim b/bundle/vim-haxe/syntax/haxe.vim new file mode 100644 index 000000000..243e33025 --- /dev/null +++ b/bundle/vim-haxe/syntax/haxe.vim @@ -0,0 +1,268 @@ +" Vim syntax file +" Language: Haxe +" Maintainer: Luca Deltodesco +" Last Change: 2013 August 26 + +if exists("b:current_syntax") + finish +endif + +" provide fallback HiLink command +if version < 508 + command! -nargs=+ HaxeHiLink hi link +else + command! -nargs=+ HaxeHiLink hi def link +endif + +" characters that cannot be in a haxe program (outside a string) +syn match haxeError "[\\`]" + +" keywords +" -------- +syn keyword haxeTypedef typedef extends implements +syn keyword haxeTypeDecl class enum abstract interface import using package from to +syn keyword haxeStorageClass static inline public private macro dynamic extern override final + +syn match haxeTypedef "\.\s*\"ms=s+1 +syn match haxeTypeDecl "^class\>" +syn match haxeTypeDecl "[^.]\s*\"ms=s+1 + +syn keyword haxeException try catch throw +syn keyword haxeRepeat for do while in +syn keyword haxeLabel case +syn keyword haxeConditional switch +syn match haxeConditional "\<\#\@" +syn keyword haxeConstant null never super this default get set +syn keyword haxeFunction function __dollar__new new +syn match haxeFunction "\<__[^_]\+__\>" +syn keyword haxeKeyword untyped cast continue break return trace var +syn match haxeKeyword "\$type" + +syn match haxeError "\<#\@" + +" type identifiers +" ---------------- +syn match haxeType "\<[A-Z][a-zA-Z_0-9]*\>" + +" operators +" --------- +" Did a lot of work here to ensure a lot of invalid operators are highlighted as errors. + +" put ,; in seperate highlight group to .: to avoid mistakes. +syn match haxeOperator "[:?]" +syn match haxeOperator2 "[;,]" + +" match . and ... as operators, and .. and more than 4 . as errors +syn match haxeOperator "\.\@,<<,>>,>>> as operators +syn match haxeOperator ">\@\|>>\|>>>\)>\@!" +syn match haxeOperator "<\@)=? as operators +" have to match &!<> seperate to avoid highlighting things like &&= &&& <<< as okay +syn match haxeOperator "[+\-*/%^!]=\?=\@!" +syn match haxeOperator "<\@\@]=\?[=>]\@!" +syn match haxeOperator "&\@" +syn match haxeFloat "\<\([\-+]\?[0-9]*\.\?[0-9]\+([eE][\-+]\?[0-9]\+)\?\)\>" +syn keyword haxeBool true false + +" comments +" -------- +syn keyword haxeTODO contained TODO FIXME XXX +syn match haxeComment "//.*" contains=haxeTODO,@Spell +syn region haxeComment2 start=+/\*+ end=+\*/+ contains=haxeTODO,@Spell + +" preprocessing +" ------------- +syn match haxePre "\(#if\|#elseif\|#else\|#end\)" +syn match haxePreError "#error" + +" regex +" ----- +syn region haxeRegex start=+\~\/+ end=+\/+ contains=haxeRegexEscape,haxeRegexError,@Spell + +syn match haxeRegexError contained "\\[^0-9bdnrstwxBDSW(){}\[\]\\$^*\-+|./?]" +syn match haxeRegexEscape contained "\\[0-9bdnrstwxBDSW(){}\[\]\\$^*\-+|./?]" + +" meta +" ---- +syn match haxeMeta "@:\?[a-zA-Z_][a-zA-Z_0-9]*\>" + +syn match haxeCompilerMeta "@:\( + \abstract + \\|access + \\|allow + \\|annotation + \\|arrayAccess + \\|autoBuild + \\|bind + \\|bitmap + \\|build + \\|buildXml + \\|callable + \\|classCode + \\|commutative + \\|compilerGenerated + \\|coreApi + \\|coreType + \\|cppFileCode + \\|cppNamespaceCode + \\|dce + \\|debug + \\|decl + \\|defParam + \\|delegate + \\|depend + \\|deprecated + \\|event + \\|enum + \\|expose + \\|extern + \\|fakeEnum + \\|file + \\|final + \\|font + \\|forward + \\|from + \\|functionCode + \\|functionTailCode + \\|generic + \\|genericBuild + \\|getter + \\|hack + \\|headerClassCode + \\|headerCode + \\|headerNamespaceCode + \\|hxGen + \\|ifFeature + \\|include + \\|initPackage + \\|internal + \\|isVar + \\|jsRequire + \\|keep + \\|keepInit + \\|keepSub + \\|luaRequire + \\|macro + \\|meta + \\|multiType + \\|multiReturn + \\|native + \\|nativeGen + \\|noCompletion + \\|noDebug + \\|noDoc + \\|noImportGlobal + \\|noPackageRestrict + \\|noStack + \\|noUsing + \\|notNull + \\|ns + \\|op + \\|optional + \\|overload + \\|privateAccess + \\|property + \\|protected + \\|public + \\|publicFields + \\|readOnly + \\|remove + \\|require + \\|rtti + \\|runtime + \\|runtimeValue + \\|selfCall + \\|setter + \\|sound + \\|struct + \\|suppressWarnings + \\|throws + \\|to + \\|transient + \\|unbound + \\|unifyMinDynamic + \\|unreflective + \\|unsafe + \\|usage + \\|volatile + \\)\>" + + +syn sync ccomment haxeComment2 minlines=10 + +HaxeHiLink haxeMeta Macro +HaxeHiLink haxeCompilerMeta Identifier +HaxeHiLink haxeRegex String +HaxeHiLink haxeDString String +HaxeHiLink haxeSString Character +HaxeHiLink haxeSpecialCharacter SpecialChar +HaxeHiLink haxeIntSpecialChar SpecialChar +HaxeHiLink haxeRegexEscape SpecialChar +HaxeHiLink haxeErrorCharacter Error +HaxeHiLink haxeRegexError Error +HaxeHiLink haxeInterpolatedIdent Normal +HaxeHiLink haxeInterpolated Normal +HaxeHiLink haxeError Error +HaxeHiLink haxeOperator Operator +HaxeHiLink haxeOperator2 Identifier +HaxeHiLink haxeSpecial SpecialChar +HaxeHiLink haxeInt Number +HaxeHiLink haxeFloat Float +HaxeHiLink haxeBool Boolean +HaxeHiLink haxeComment Comment +HaxeHiLink haxeComment2 Comment +HaxeHiLink haxeTODO Todo +HaxeHiLink haxePre PreCondit +HaxeHiLink haxePreError PreProc +HaxeHiLink haxeType Type +HaxeHiLink haxeTypedef Typedef +HaxeHiLink haxeTypeDecl Keyword " Structure just gives me same colour as Type and looks bad. +HaxeHiLink haxeStorageClass StorageClass +HaxeHiLink haxeException Exception +HaxeHiLink haxeRepeat Repeat +HaxeHiLink haxeLabel Label +HaxeHiLink haxeConditional Conditional +HaxeHiLink haxeConstant Constant +HaxeHiLink haxeFunction Function +HaxeHiLink haxeKeyword Keyword + +delcommand HaxeHiLink + +let b:current_syntax = "haxe" +let b:spell_options = "contained" + + +" vim: ts=8 diff --git a/bundle/vim-haxe/syntax/haxe_extended.vim b/bundle/vim-haxe/syntax/haxe_extended.vim new file mode 100644 index 000000000..abc6899b7 --- /dev/null +++ b/bundle/vim-haxe/syntax/haxe_extended.vim @@ -0,0 +1,127 @@ + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Haxedoc +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if exists("haxe_haxedoc") || (exists("main_syntax") && main_syntax == 'jsp') + syntax case ignore + " syntax coloring for haxedoc comments (HTML) + " syntax include @haxeHtml :p:h/html.vim + " unlet b:current_syntax + syn region haxeDocComment start="/\*\*" end="\*/" keepend contains=haxeCommentTitle,@haxeHtml,haxeDocTags,haxeTodo,@Spell + syn region haxeCommentTitle contained matchgroup=haxeDocComment start="/\*\*" matchgroup=haxeCommentTitle keepend end="\.$" end="\.[ \t\r<&]"me=e-1 end="[^{]@"me=s-2,he=s-1 end="\*/"me=s-1,he=s-1 contains=@haxeHtml,haxeCommentStar,haxeTodo,@Spell,haxeDocTags + + syn region haxeDocTags contained start="{@\(link\|linkplain\|inherit[Dd]oc\|doc[rR]oot\|value\)" end="}" + syn match haxeDocTags contained "@\(see\|param\|exception\|throws\|since\)\s\+\S\+" contains=haxeDocParam + syn match haxeDocParam contained "\s\S\+" + syn match haxeDocTags contained "@\(version\|author\|return\|deprecated\|serial\|serialField\|serialData\)\>" + syntax case match + HaxeHiLink haxeDocComment Comment + HaxeHiLink haxeDocTags Special + HaxeHiLink haxeDocParam Function +endif + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Haxe comment strings +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if exists("haxe_comment_strings") + syn region haxeCommentString contained start=+"+ end=+"+ end=+$+ end=+\*/+me=s-1,he=s-1 contains=haxeSpecial,haxeCommentStar,haxeSpecialChar,@Spell + syn region haxeComment2String contained start=+"+ end=+$\|"+ contains=haxeSpecial,haxeSpecialChar,@Spell + syn match haxeCommentCharacter contained "'\\[^']\{1,6\}'" contains=haxeSpecialChar + syn match haxeCommentCharacter contained "'\\''" contains=haxeSpecialChar + syn match haxeCommentCharacter contained "'[^\\]'" + syn cluster haxeCommentSpecial add=haxeCommentString,haxeCommentCharacter,haxeNumber + syn cluster haxeCommentSpecial2 add=haxeComment2String,haxeCommentCharacter,haxeNumber + HaxeHiLink haxeCommentString haxeString + HaxeHiLink haxeComment2String haxeString +endif + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Haxe concealed text +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if exists('g:haxe_conceal') && has("conceal") + syn match Ignore 'urn' transparent conceal containedin=haxeStatement + syn match Ignore 'ction' transparent conceal containedin=haxeStorageClass,haxeStatement + syn match Ignore 'ati' transparent conceal containedin=haxeStorageClass + syn match Ignore 'nline\|tati\|ubli' transparent conceal containedin=haxeScopeDecl +endif + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Haxe space errors +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if exists("haxe_space_errors") + if !exists("haxe_no_trail_space_error") + syn match haxeSpaceError "\s\+$" + endif + if !exists("haxe_no_tab_space_error") + syn match haxeSpaceError " \+\t"me=e-1 + endif + HaxeHiLink haxeSpaceError Error +endif + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Haxe minline comments +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if !exists("haxe_minlines") + let haxe_minlines = 10 + exec "syn sync ccomment haxeComment minlines=" . haxe_minlines +endif + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Mark braces in parens as errors +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if exists("haxe_mark_braces_in_parens_as_errors") + syn match haxeInParen contained "[{}]" + HaxeHiLink haxeInParen haxeError + syn cluster haxeTop add=haxeInParen +endif + + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Highlight Functions +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if exists("haxe_highlight_functions") + if haxe_highlight_functions == "indent" + syn match haxeFuncDef "^\(\t\| \{8\}\)[_$a-zA-Z][_$a-zA-Z0-9_. \[\]]*([^-+*/()]*)" contains=haxeScopeDecl,haxeType,haxeStorageClass,@haxeClasses + syn region haxeFuncDef start=+^\(\t\| \{8\}\)[$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*,\s*+ end=+)+ contains=haxeScopeDecl,haxeType,haxeStorageClass,@haxeClasses + syn match haxeFuncDef "^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*)" contains=haxeScopeDecl,haxeType,haxeStorageClass,@haxeClasses + syn region haxeFuncDef start=+^ [$_a-zA-Z][$_a-zA-Z0-9_. \[\]]*([^-+*/()]*,\s*+ end=+)+ contains=haxeScopeDecl,haxeType,haxeStorageClass,@haxeClasses + else + " This line catches method declarations at any indentation>0, but it assumes + " two things: + " 1. class names are always capitalized (ie: Button) + " 2. method names are never capitalized (except constructors, of course) + syn region haxeFuncDef start=+^\s\+\(\(public\|protected\|private\|static\|abstract\|override\|final\|native\|synchronized\)\s\+\)*\(\(void\|boolean\|char\|byte\|short\|int\|long\|float\|double\|\([A-Za-z_][A-Za-z0-9_$]*\.\)*[A-Z][A-Za-z0-9_$]*\)\(\[\]\)*\s\+[a-z][A-Za-z0-9_$]*\|[A-Z][A-Za-z0-9_$]*\)\s*(+ end=+)+ contains=haxeScopeDecl,haxeType,haxeStorageClass,haxeComment,haxeLineComment,@haxeClasses + endif + syn match haxeBraces "[{}]" + syn cluster haxeTop add=haxeFuncDef,haxeBraces +endif + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Add special handling for haxecc.vim +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" use separate name so that it can be deleted in haxecc.vim +syn match haxeError2 "#\|=<" +HaxeHiLink haxeError2 haxeError + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" Catch extra paren errors +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" catch errors caused by wrong parenthesis +syn region haxeParenT transparent matchgroup=haxeParen start="(" end=")" contains=@haxeTop,haxeParenT1,haxeString,haxeSingleString +syn region haxeParenT1 transparent matchgroup=haxeParen1 start="(" end=")" contains=@haxeTop,haxeParenT2 contained +syn region haxeParenT2 transparent matchgroup=haxeParen2 start="(" end=")" contains=@haxeTop,haxeParenT contained +syn match haxeParenError ")" +HaxeHiLink haxeParenError haxeError + + +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +" load a spearte haxeid.vim file +""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" +if filereadable(expand(":p:h")."/haxeid.vim") + source :p:h/haxeid.vim +endif diff --git a/bundle/vim-haxe/syntax/hss.vim b/bundle/vim-haxe/syntax/hss.vim new file mode 100644 index 000000000..dbb7988ce --- /dev/null +++ b/bundle/vim-haxe/syntax/hss.vim @@ -0,0 +1,111 @@ +" Vim syntax file +" Language: hss (Haxe css) +" Author: Justin Donaldson (jdonaldson@gmail.com) +" Based heavily on work by Daniel Hofstetter (daniel.hofstetter@42dh.com) + +if !exists("main_syntax") + if version < 600 + syntax clear + elseif exists("b:current_syntax") + finish + endif + let main_syntax = 'hss' +endif + +runtime! syntax/css.vim +runtime! syntax/css/*.vim + +syn case ignore + +syn region hssDefinition transparent matchgroup=cssBraces start='{' end='}' contains=css.*Attr,css.*Prop,cssComment,cssValue.*,cssColor,cssUrl,cssImportant,cssError,cssStringQ,cssStringQQ,cssFunction,cssUnicodeEscape,hssDefinition,hssComment,hssIdChar,hssClassChar,hssAmpersand,hssVariable,hssInclude,hssExtend,hssDebug,hssWarn,@hssControl,hssInterpolation,hssNestedSelector,hssReturn + +syn region hssInterpolation start="#{" end="}" contains=hssVariable + +syn match hssVariable "$[[:alnum:]_-]\+" nextgroup=hssVariableAssignment +syn match hssVariableAssignment ":" contained nextgroup=hssVariableValue +syn match hssVariableValue ".*;"me=e-1 contained contains=hssVariable,hssOperator,hssDefault "me=e-1 means that the last char of the pattern is not highlighted +" syn match hssMixin "^@mixin" nextgroup=hssMixinName +syn match hssMixinName " [[:alnum:]_-]\+" contained nextgroup=hssDefinition +syn match hssFunction "^@function" nextgroup=hssFunctionName +syn match hssFunctionName " [[:alnum:]_-]\+" contained nextgroup=hssDefinition +" syn match hssReturn "@return" contained +" syn match hssInclude "@include" nextgroup=hssMixinName +" syn match hssExtend "@extend .*[;}]"me=e-1 contains=cssTagName,hssIdChar,hssClassChar +syn keyword hssTodo TODO FIXME NOTE OPTIMIZE XXX contained containedIn=hssComment,cssComment + +syn match hssColor "#[0-9A-Fa-f]\{3\}\>" contained +syn match hssColor "#[0-9A-Fa-f]\{6\}\>" contained + +syn match hssIdChar "#[[:alnum:]_-]\@=" nextgroup=hssId contains=hssColor +syn match hssId "[[:alnum:]_-]\+" contained +syn match hssClassChar "\.[[:alnum:]_-]\@=" nextgroup=hssClass +syn match hssClass "[[:alnum:]_-]\+" contained +syn match hssAmpersand "&" nextgroup=cssPseudoClass + +syn match hssOperator "+" contained +syn match hssOperator "-" contained +syn match hssOperator "/" contained +syn match hssOperator "*" contained + +syn match hssNestedSelector "[^/]* {"me=e-1 contained contains=cssTagName,cssAttributeSelector,hssIdChar,hssClassChar,hssAmpersand,hssVariable,hssMixin,hssFunction,@hssControl,hssInterpolation,hssNestedProperty +syn match hssNestedProperty "[[:alnum:]]\+:"me=e-1 contained + +" syn match hssDebug "@debug" +" syn match hssWarn "@warn" +syn match hssDefault "!default" contained + +" syn match hssIf "@if" +" syn match hssElse "@else" +" syn match hssElseIf "@else if" +" syn match hssWhile "@while" +" syn match hssFor "@for" nextgroup=hssVariable +" syn match hssFrom " from " +" syn match hssTo " to " +" syn match hssThrough " through " +" syn match hssEach "@each" nextgroup=hssVariable +" syn match hssIn " in " +" syn cluster hssControl contains=hssIf,hssElse,hssElseIf,hssWhile,hssFor,hssFrom,hssTo,hssThrough,hssEach,hssIn + +syn match hssComment "//.*$" contains=@Spell +syn region hssImportStr start="\"" end="\"" +syn region hssImport start="@import" end=";" contains=hssImportStr,hssComment,cssComment,cssUnicodeEscape,cssMediaType + +hi def link hssVariable Identifier +hi def link hssVariableValue Constant +hi def link hssMixin PreProc +hi def link hssMixinName Function +hi def link hssFunction PreProc +hi def link hssFunctionName Function +hi def link hssReturn Statement +hi def link hssInclude PreProc +hi def link hssExtend PreProc +hi def link hssComment Comment +hi def link hssColor Constant +hi def link hssIdChar Special +hi def link hssClassChar Special +hi def link hssId Identifier +hi def link hssClass Identifier +hi def link hssAmpersand Character +hi def link hssNestedProperty Type +hi def link hssDebug Debug +hi def link hssWarn Debug +hi def link hssDefault Special +hi def link hssIf Conditional +hi def link hssElse Conditional +hi def link hssElseIf Conditional +hi def link hssWhile Repeat +hi def link hssFor Repeat +hi def link hssFrom Repeat +hi def link hssTo Repeat +hi def link hssThrough Repeat +hi def link hssEach Repeat +hi def link hssIn Repeat +hi def link hssInterpolation Delimiter +hi def link hssImport Include +hi def link hssImportStr Include +hi def link hssTodo Todo + +let b:current_syntax = "hss" +if main_syntax == 'hss' + unlet main_syntax +endif diff --git a/bundle/vim-haxe/syntax/hxml.vim b/bundle/vim-haxe/syntax/hxml.vim new file mode 100644 index 000000000..88a9fd2b1 --- /dev/null +++ b/bundle/vim-haxe/syntax/hxml.vim @@ -0,0 +1,86 @@ +" Vim syntax file +" Author : Justin Donaldson (jdonaldson@gmail.com) +" Based extensively on a version by Ganesh Gunasegaran(me at itsgg.com) +" Language : hxml + +if !exists("main_syntax") + if version < 600 + syntax clear + elseif exists("b:current_syntax") + finish + endif + let main_syntax='hxml' +endif + +" Simple TODO/comment handling +syntax keyword hxmlTodo contained TODO FIXME XXX NOTE +syntax match hxmlComment "#.*$" contains=hxmlTodo + +" basic flags +syntax match hxmlType "-v" +syntax match hxmlType "-x" +syntax match hxmlType "-D" + +"target/config flags +syntax match hxmlType "--\?as3" +syntax match hxmlType "--\?cmd" +syntax match hxmlType "--\?cp" +syntax match hxmlType "--\?cpp" +syntax match hxmlType "--\?cppia" +syntax match hxmlType "--\?java" +syntax match hxmlType "--\?cs" +syntax match hxmlType "--\?debug" +syntax match hxmlType "--\?help" +syntax match hxmlType "--\?js" +syntax match hxmlType "--\?lib" +syntax match hxmlType "--\?lua" +syntax match hxmlType "--\?main" +syntax match hxmlType "--\?neko" +syntax match hxmlType "--\?php" +syntax match hxmlType "--\?python" +syntax match hxmlType "--\?prompt" +syntax match hxmlType "--\?resource" +syntax match hxmlType "--\?swf" +syntax match hxmlType "--\?swf-header" +syntax match hxmlType "--\?swf-lib" +syntax match hxmlType "--\?swf-version" +syntax match hxmlType "--\?swf9" +syntax match hxmlType "--\?xml" + +" haxe 3.0 flags +syntax match hxmlType "--/?dce" +syntax match hxmlType "--/?swf-lib-extern" +syntax match hxmlType "--/?version" +syntax match hxmlType "--/?help-metas" +syntax match hxmlType "--/?help-defines" + +" advanced flags +syntax match hxmlStatement "--connect" +syntax match hxmlStatement "--cwd" +syntax match hxmlStatement "--dead-code-elimination" +syntax match hxmlStatement "--display" +syntax match hxmlStatement "--flash-strict" +syntax match hxmlStatement "--flash-use-stage" +syntax match hxmlStatement "--gen-hx-classes" +syntax match hxmlStatement "--help" +syntax match hxmlStatement "--interp" +syntax match hxmlStatement "--js-modern" +syntax match hxmlStatement "--macro" +syntax match hxmlStatement "--next" +syntax match hxmlStatement "--no-inline" +syntax match hxmlStatement "--no-opt" +syntax match hxmlStatement "--no-output" +syntax match hxmlStatement "--no-traces" +syntax match hxmlStatement "--php-front" +syntax match hxmlStatement "--php-lib" +syntax match hxmlStatement "--php-prefix" +syntax match hxmlStatement "--remap" +syntax match hxmlStatement "--times" +syntax match hxmlStatement "--wait" + + +" Highlight them +highlight link hxmlType Type +highlight link hxmlStatement Statement +highlight link hxmlComment Comment +highlight link hxmlTodo Todo diff --git a/bundle/vim-haxe/tools/add_remote.sh b/bundle/vim-haxe/tools/add_remote.sh new file mode 100644 index 000000000..7be89454e --- /dev/null +++ b/bundle/vim-haxe/tools/add_remote.sh @@ -0,0 +1 @@ +git remote add vimsyntax https://github.com/jdonaldson/vim-haxe-syntax.git diff --git a/bundle/vim-haxe/tools/create_ultisnips.sh b/bundle/vim-haxe/tools/create_ultisnips.sh new file mode 100644 index 000000000..2a5d8dbd0 --- /dev/null +++ b/bundle/vim-haxe/tools/create_ultisnips.sh @@ -0,0 +1,14 @@ +target_dir=~/.vim/bundle/vaxe/ultisnips +source_dir=~/.vim/bundle/vaxe/snippets +filetypes=(haxe nmml hxml) + +for target_ft in ${filetypes[*]} +do + mkdir -p $target_dir + ULTISNIPS_OUTPUT=$target_dir/$target_ft.snippets + ULTISNIPS_SOURCE=$source_dir/$target_ft.snippets + python ~/.vim/bundle/Ultisnips/utils/convert_snipmate_snippets.py $ULTISNIPS_SOURCE > $ULTISNIPS_OUTPUT + echo '# This file is autogenerated by tools/create_ultisnips.sh, any edits will be overwritten. +# (Edit' $ULTISNIPS_SOURCE 'instead.)' | cat - $ULTISNIPS_OUTPUT > temp && mv temp $ULTISNIPS_OUTPUT +done + diff --git a/bundle/vim-haxe/tools/pull_syntax.sh b/bundle/vim-haxe/tools/pull_syntax.sh new file mode 100644 index 000000000..594ddf6d8 --- /dev/null +++ b/bundle/vim-haxe/tools/pull_syntax.sh @@ -0,0 +1,2 @@ +git fetch vimsyntax master +git subtree pull --prefix=syntax --squash vimsyntax master diff --git a/bundle/vim-haxe/tools/push_syntax.xh b/bundle/vim-haxe/tools/push_syntax.xh new file mode 100644 index 000000000..b39157be4 --- /dev/null +++ b/bundle/vim-haxe/tools/push_syntax.xh @@ -0,0 +1 @@ +git subtree push --prefix=syntax --squash vimsyntax master diff --git a/bundle/vim-haxe/ultisnips/haxe.snippets b/bundle/vim-haxe/ultisnips/haxe.snippets new file mode 100644 index 000000000..efbae0288 --- /dev/null +++ b/bundle/vim-haxe/ultisnips/haxe.snippets @@ -0,0 +1,132 @@ +# This file is autogenerated by tools/create_ultisnips.sh, any edits will be overwritten. +# (Edit /Users/jdonaldson/.vim/bundle/vaxe/snippets/haxe.snippets instead.) +snippet doc "doc" +/** + ${1} + **/ +endsnippet + +snippet switch "switch" +switch(${1}){ + case ${2}: ${3} +} +endsnippet + +snippet case "case" +case ${1}: ${2} +endsnippet + +snippet try "try" +try{ + ${1} +}catch(e:${2}){ + ${3:// Ignore any errors.} +} +endsnippet + +snippet for "for" +for( ${1:var} in ${2:itr} ){ + ${3} +} +endsnippet + +snippet class "HAXE" +class `!v expand('%:t:r')` { + public function new(${1}) { + ${2://initialize variables} + } + static function main() { + ${3:trace("hello world");} + } +} +endsnippet + +snippet main "main" +static function main() { + ${1:trace("hello world");} +} +endsnippet + +snippet new "new" +public function new(${1:arg}) { + super($1); +} +endsnippet + +snippet fn "func" +function(${1:arg}) { + ${2} +} +endsnippet + +snippet fu "function" +function ${1:name}(${2:arg}) { + ${3} +} +endsnippet + +snippet prifu "private function" +private function ${1:name}(${2:arg}) { + ${3} +} +endsnippet + +snippet pufu "public function" +public function ${1:name}(${2:arg}) { + ${3} +} +endsnippet + +snippet pustafu "public static function" +public static function ${1:name}(${2:arg}) { + ${3} +} +endsnippet + +snippet pristafu "private static function" +private static function ${1:name}(${2:arg}) { + ${3} +} +endsnippet + +snippet trace "trace" +trace(${1}); +endsnippet + +snippet desc "function" +trace(${1} + " is the value for $1"); +endsnippet + +snippet cast "cast" +cast(${1:cast_this}, ${2:type}) +endsnippet + +snippet interface "interface" +interface ${1:name}${2: implements this}${3:, implements other}{ + ${4} +} +endsnippet + +snippet #if "#if" +#if js, php, cpp, flash +${1} +#end{2} +endsnippet + +snippet typedef "typedef" +typedef ${1}${2:} = { + var ${3}:$2; +}${4} +endsnippet + +snippet untyped "untyped" +untyped{ ${1} }${2} +endsnippet + +snippet enum "enum" +enum ${1:Name} { + ${2:Construct} +} +endsnippet + + diff --git a/bundle/vim-haxe/ultisnips/hxml.snippets b/bundle/vim-haxe/ultisnips/hxml.snippets new file mode 100644 index 000000000..bcde911b9 --- /dev/null +++ b/bundle/vim-haxe/ultisnips/hxml.snippets @@ -0,0 +1,67 @@ +# This file is autogenerated by tools/create_ultisnips.sh, any edits will be overwritten. +# (Edit /Users/jdonaldson/.vim/bundle/vaxe/snippets/hxml.snippets instead.) +snippet resource "resource" +-resource ${1:file}${2:@name(optional)} +endsnippet + +snippet neko "neko" +-main ${1:Main} +-neko ${2:bin/}$1.n +endsnippet + +snippet flash9 "flash9" +-main ${1:Main} +-swf9 ${2:bin/}$1.v9.swf +endsnippet + +snippet flash "flash" +-main ${1:Main} +-swf ${2:bin/}$1.swf +endsnippet + +snippet php "php" +-main ${1:Main} +-php php +endsnippet + +snippet js "js" +-main ${1:Main} +-js $2$1.js +endsnippet + +snippet cpp "cpp" +-main ${1:Main} +-cpp cpp +endsnippet + +snippet remap "remap" +--remap ${1:neko}:$2 +endsnippet + +snippet all "all" +-main ${1:Main} +-neko ${2:bin/}$1.n +${3:} +--next +-main $1 +-swf9 $2$1.v9.swf +$3 +--next +-main $1 +-swf $2$1.v8.swf +$3 +--next +-main $1 +-php php +$3 +--next +-main $1 +-js $2$1.js +$3 +--next +-main $1 +-cpp cpp +$3 +endsnippet + + diff --git a/bundle/vim-haxe/ultisnips/nmml.snippets b/bundle/vim-haxe/ultisnips/nmml.snippets new file mode 100644 index 000000000..30a8dae4d --- /dev/null +++ b/bundle/vim-haxe/ultisnips/nmml.snippets @@ -0,0 +1,60 @@ +# This file is autogenerated by tools/create_ultisnips.sh, any edits will be overwritten. +# (Edit /Users/jdonaldson/.vim/bundle/vaxe/snippets/nmml.snippets instead.) +snippet meta "meta" + +endsnippet + +snippet app "app" + +endsnippet + +snippet assets "assets" + +endsnippet + +snippet graphics "graphics" + +endsnippet + +snippet audio "audio" + + +endsnippet + +snippet font "font" + +endsnippet + +snippet source "source" + +endsnippet + +snippet lib "lib" + +endsnippet + +snippet fps "fps" + +endsnippet + +snippet fullscren "fullscren" + +endsnippet + +snippet window "window" + +endsnippet + +snippet haxeflag "haxeflag" + +endsnippet + +snippet ndll "ndll" + +endsnippet + +snippet icon "icon" + +endsnippet + +