Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Another take on projectionist config #1

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
b9cfc31
Folding tests (#453)
schnittchen Dec 6, 2018
34873ee
replace all indent tests with i helper (#455)
jbodah Dec 6, 2018
7e65a35
Fix syntax highlighting with "~S" sigil (#457)
feliperenan Dec 12, 2018
49ca9b9
Add .xrl to the suffixes list (#461)
jparise Dec 28, 2018
c259418
Fix issue-459 (#460)
veita Dec 28, 2018
da5bc2c
add failing spec for implicit rescues
Dec 28, 2018
3c5060d
Revert "add failing spec for implicit rescues"
Dec 28, 2018
ca6759f
try else indent (#462)
jbodah Dec 28, 2018
cf5cf15
remove pending flag from test
Dec 28, 2018
c1c3dca
remove pending guard syntax tests
Dec 28, 2018
168815d
fix if/else folding bug (#468)
jbodah Dec 31, 2018
0f4e2da
speed up fold tests
Dec 31, 2018
03d1486
speed up vim start
Dec 31, 2018
e2be90d
micro optimizations for tests
Dec 31, 2018
3abb0f4
Use 'set filetype' to set filetype once again (#467)
jparise Feb 12, 2019
b92fc03
Add vim 8 package manager instructions (#449)
lukebakken Feb 12, 2019
a4991c9
Syntax: Add doc delimiters (#470)
endersstocker Feb 12, 2019
9b466fd
Remove redundant 'formatoptions' setting (#472)
jparise Feb 13, 2019
653cc4d
Use 'setfiletype' to set local &filetype (#473)
jparise Feb 13, 2019
af0b49a
Revert "Use 'setfiletype' to set local &filetype (#473)" (#476)
jbodah Feb 14, 2019
f17537d
split up write/redraw in test suite to improve reliability
jbodah Feb 14, 2019
b6990d9
Syntax: Add private declarations (#471)
endersstocker Feb 14, 2019
d5d4400
Fix wrong highlight of paren after `defmodule` (#478)
dreamtigers Feb 27, 2019
9724749
Update README.md vim 8 install instructions (#480)
navargas Mar 4, 2019
d58efec
vim-dadbod integration for applications using Ecto (#481)
hauleth Mar 13, 2019
d51d5f7
add support for live view templates (#483)
cadebward Mar 18, 2019
fbab531
syntax: Allow escaping of doc heredocs (#489)
liskin Apr 17, 2019
7e00da6
Add Phoenix LiveEEx Template (.leex) file type support (2) (#490)
jbodah Apr 17, 2019
24a0072
add docker container file with isolated vim instance
Apr 25, 2019
8e4782f
Update README.md
jbodah Apr 25, 2019
9f9deef
ftdetect: Fix detection when reopening
liskin Apr 25, 2019
c5d6345
syntax: Fix uppercase Atom: in keyword lists
liskin Apr 30, 2019
98c0304
syntax: Highlight dots in aliases as aliases
liskin Apr 30, 2019
38e8bbf
add nvim to docker-compose
May 14, 2019
a219dc1
Set mix.lock as Elixir
dbernheisel Jun 27, 2019
2e3b3b2
Introduce initial doc
ujihisa Jul 20, 2019
46a6847
Do not change &formatprg globally
ujihisa Jul 20, 2019
1b7f422
Ensure right string matching case for elixirExUnit* patterns
kassio Aug 15, 2019
30e764f
Reading column number on credo errors
kelvinst Aug 21, 2019
c936563
syntax: Prevent syntax/html.vim from overriding our syn sync
liskin May 14, 2019
1c47961
syntax: Prevent syntax/javascript.vim from overriding our syn sync
liskin May 14, 2019
8bdf686
syntax: Fix elixir_use_markdown_for_docs
liskin May 14, 2019
edf94f7
Using mix compile, not mix as makeprg for mix compiler
kelvinst Aug 21, 2019
e9d495b
Improving the error format for mix compile
kelvinst Aug 21, 2019
eb06df6
Fix highlight for atoms containing @ character
Sep 2, 2019
2f276ab
Revert "Fix highlight for atoms containing @ character"
jbodah Sep 3, 2019
008b224
Fix doc sigil with paren
jbodah Sep 6, 2019
e8d59d1
don't change indent of doc blocks, strings, and comments
jbodah Sep 6, 2019
057ac39
Syntax: add __STACKTRACE__ (#514)
hauleth Nov 3, 2019
95a0e08
Add ctags to gitignore
pksunkara Feb 10, 2020
7b23001
Use /usr/bin/env to find bash
oleks Jan 23, 2020
a7f4225
Add raise as keyword
Sgiath Feb 19, 2020
85afa5e
Move test to one it
Sgiath Feb 19, 2020
088cfc4
add elixirFunctionCall
jbodah Mar 11, 2020
47d05df
Add tilde operators syntax matches
aoswalt Mar 27, 2020
942a17d
light brush up of README
jbodah Apr 17, 2020
f1f525e
add feature wishlist to README
jbodah Apr 17, 2020
084d184
tweak maintenance help wording
jbodah Apr 17, 2020
80f0dae
add configuration tips to README
jbodah Apr 18, 2020
d1d3688
README.md typo fix
szTheory Apr 25, 2020
53c530f
README.md update git clone URLs
szTheory Apr 25, 2020
6acef30
Add basic projectionist support
mluts Nov 2, 2018
f8890cf
Another take on projectionist config
kelvinst Aug 21, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
profile.log
test_indent.result
doc/tags
5 changes: 5 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM ubuntu:latest

RUN apt-get update && apt-get install -yf vim

COPY test.vimrc /root/.vimrc
8 changes: 8 additions & 0 deletions Dockerfile.nvim
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# vi: ft=dockerfile
FROM ubuntu:latest

RUN apt-get update && apt-get install -yf neovim

RUN mkdir -p /root/.config/nvim

COPY test.init.vim /root/.config/nvim/init.vim
85 changes: 72 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,101 @@
Features:

* Syntax highlighting for Elixir and EEx files
* Filetype detection for `.ex`, `.exs` and `.eex` files
* Filetype detection for `.ex`, `.exs`, `.eex` and `.leex` files
* Automatic indentation
* Integration between Ecto projects and [vim-dadbod][] for running SQL queries
on defined Ecto repositories

## Installation

`vim-elixir` can be installed either with a plugin manager or by directly copying the files into your vim folders (location varies between platforms)

### Plugin Managers

If you are using a plugin manager then add `vim-elixir` the way you would any other plugin:

```bash
# pathogen
git clone https://github.com/elixir-lang/vim-elixir.git ~/.vim/bundle/vim-elixir
# Using vim 8 native package loading
# http://vimhelp.appspot.com/repeat.txt.html#packages
git clone https://github.com/elixir-editors/vim-elixir.git ~/.vim/pack/my-packages/start/vim-elixir

# Using pathogen
git clone https://github.com/elixir-editors/vim-elixir.git ~/.vim/bundle/vim-elixir
```

```viml
" vim-plug
" Using vim-plug
Plug 'elixir-editors/vim-elixir'

" Vundle
" Using Vundle
Plugin 'elixir-editors/vim-elixir'

" NeoBundle
" Using NeoBundle
NeoBundle 'elixir-editors/vim-elixir'
```

### Manual installation
### Manual Installation

If you are not using a package manager then you can use the provided `manual_install.sh` script to copy the files into their respective homes.

Run [./manual_install.sh](manual_install.sh) to copy the contents of each directory in the respective directories inside `~/.vim`.

## Configuration

You must add the following to your `~/.vimrc`:

```
" Enable syntax highlighting
syntax on

" Enables filetype detection, loads ftplugin, and loads indent
" (Not necessary on nvim and may not be necessary on vim 8.2+)
filetype plugin indent on
```

Run [./manual_install.sh](manual_install.sh) to copy the contents of each directory in the respective directories inside
`~/.vim`.
## Notes/Caveats

## `mix format` Integration
### `mix format` Integration

We've decided not to include `mix format` integration into `vim-elixir`. If you'd like to set it up yourself, you have the following options:
We've decided not to include `mix format` integration into `vim-elixir`.
If you'd like to set it up yourself, you have the following options:

* For asynchronous execution of the formatter, have a look at [vim-mix-format](https://github.com/mhinz/vim-mix-format)
* Add it as a `formatprg` (e.g. `set formatprg=mix\ format\ -`)
* Add it as a `formatprg` (e.g. `setlocal formatprg=mix\ format\ -`)

Why isn't this supported? We've run into two major issues with calling out to `mix format`.
First `mix format` would not work unless your program compiled.
Second `mix format` added an external process dependency to `vim-elixir`.

If someone really wanted to try and add this then we might be able to model it after `vim-go`'s `go fmt` integration
which I think could be acceptable to merge into master.

## Development

### Maintenance Help

`vim-elixir` is looking for new maintainers.
If you get a lot of value from it, know vimscript well, or eager to learn about it then feel free to get in touch with @jbodah (GH issue, elixir-lang Slack)

### Running the Tests

Run the tests: `bundle exec parallel_rspec spec`
Spawn a vim instance with dev configs: `bin/spawn_vim`

Spawn a container with vim and dev configs: `docker-compose build && docker-compose run vim`

### Feature Wishlist

Here is a list of features that I think would be great additions to `vim-elixir`:

* Regularly merging `vim-elixir` into `vim` and keeping the sync up-to-date
* Fixing our build so it can run regularly on CI
* Live view support
* Testing .exs files and ensuring feature compatibility between .ex and .exs
* Documentation (e.g. `:h vim-elixir`)
* README docs for various .vimrc options/flags
* Identifying and rewriting tests that conflict with `mix format`
* Fixes for indentation rule edge cases (e.g. `with`, see GH issues for examples)
* Simplifying syntax rules
* Performance optimizations for syntax/indent rules (especially for determining if something is a string)

[vim-dadbod]: https://github.com/tpope/vim-dadbod
20 changes: 20 additions & 0 deletions autoload/db/adapter/ecto.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
let s:path = expand('<sfile>:h')
let s:cmd = join(['mix', 'run', '--no-start', '--no-compile', shellescape(s:path.'/get_repos.exs')])

function! s:repo_list() abort
return map(systemlist(s:cmd), 'split(v:val)')
endfunction

function! db#adapter#ecto#canonicalize(url) abort
for l:item in s:repo_list()
let l:name = get(l:item, 0)
let l:url = get(l:item, 1)
if !empty(l:name) && 'ecto:'.l:name ==# a:url
return l:url
endif
endfor
endfunction

function! db#adapter#ecto#complete_opaque(url) abort
return map(s:repo_list(), 'v:val[0]')
endfunction
54 changes: 54 additions & 0 deletions autoload/db/adapter/get_repos.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
defmodule LoadRepos do
defp load_apps do
:code.get_path()
|> Enum.flat_map(fn app_dir ->
Path.join(app_dir, "*.app") |> Path.wildcard()
end)
|> Enum.map(fn app_file ->
app_file |> Path.basename() |> Path.rootname(".app") |> String.to_atom()
end)
|> Enum.map(&Application.load/1)
end

defp configs do
for {app, _, _} <- Application.loaded_applications(),
repos = Application.get_env(app, :ecto_repos),
is_list(repos) and repos != [],
repo <- repos,
do: {repo, Map.new(Application.get_env(app, repo))}
end

defp config_to_url(_, %{url: url}), do: url

defp config_to_url(repo, %{
hostname: hostname,
username: username,
password: password,
database: database
}) do
%URI{
scheme: adapter_to_string(repo.__adapter__),
userinfo: "#{username}:#{password}",
host: hostname,
path: Path.join("/", database)
}
|> URI.to_string()
end

defp adapter_to_string(Ecto.Adapters.Postgres), do: "postgres"
defp adapter_to_string(Ecto.Adapters.MySQL), do: "mysql"
defp adapter_to_string(mod), do: raise("Unknown adapter #{inspect(mod)}")

def main do
load_apps()

configs()
|> Enum.map(fn {repo, config} ->
[inspect(repo), ?\s, config_to_url(repo, config)]
end)
|> Enum.intersperse(?\n)
|> IO.puts()
end
end

LoadRepos.main()
26 changes: 22 additions & 4 deletions autoload/elixir/indent.vim
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ function! elixir#indent#indent(lnum)

let handlers = [
\'top_of_file',
\'starts_with_string_continuation',
\'following_trailing_binary_operator',
\'starts_with_pipe',
\'starts_with_binary_operator',
Expand All @@ -31,9 +32,14 @@ function! elixir#indent#indent(lnum)
\]
for handler in handlers
call s:debug('testing handler elixir#indent#handle_'.handler)
let context = {'lnum': lnum, 'text': text, 'prev_nb_lnum': prev_nb_lnum, 'prev_nb_text': prev_nb_text}
let context = {'lnum': lnum, 'text': text, 'first_nb_char_idx': match(text, '\w'), 'prev_nb_lnum': prev_nb_lnum, 'prev_nb_text': prev_nb_text}
let indent = function('elixir#indent#handle_'.handler)(context)
if indent != -1
if indent == -2
" Keep indent the same
call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned -2; returning indent of -1')
call cursor(curs_lnum, curs_col)
return -1
elseif indent != -1
call s:debug('line '.lnum.': elixir#indent#handle_'.handler.' returned '.indent)
call cursor(curs_lnum, curs_col)
return indent
Expand Down Expand Up @@ -98,7 +104,11 @@ endfunction
" Returns 0 or 1 based on whether or not the given line number and column
" number pair is a string or comment
function! s:is_string_or_comment(line, col)
return synIDattr(synID(a:line, a:col, 1), "name") =~ '\%(String\|Comment\)'
return s:syntax_name(a:line, a:col) =~ '\%(String\|Comment\)'
endfunction

function! s:syntax_name(line, col)
return synIDattr(synID(a:line, a:col, 1), "name")
endfunction

" Skip expression for searchpair. Returns 0 or 1 based on whether the value
Expand Down Expand Up @@ -154,6 +164,14 @@ function! elixir#indent#handle_top_of_file(context)
end
endfunction

function! elixir#indent#handle_starts_with_string_continuation(context)
if s:syntax_name(a:context.lnum, a:context.first_nb_char_idx) =~ '\(String\|Comment\)$'
return -2
else
return -1
end
endfunction

function! elixir#indent#handle_follow_prev_nb(context)
return s:get_base_indent(a:context.prev_nb_lnum, a:context.prev_nb_text)
endfunction
Expand Down Expand Up @@ -265,7 +283,7 @@ function! elixir#indent#handle_inside_block(context)
let config = {
\'f': {'aligned_clauses': s:keyword('end'), 'pattern_match_clauses': never_match},
\'c': {'aligned_clauses': s:keyword('end'), 'pattern_match_clauses': never_match},
\'t': {'aligned_clauses': s:keyword('end\|catch\|rescue\|after'), 'pattern_match_clauses': s:keyword('catch\|rescue')},
\'t': {'aligned_clauses': s:keyword('end\|catch\|rescue\|after\|else'), 'pattern_match_clauses': s:keyword('catch\|rescue\|else')},
\'r': {'aligned_clauses': s:keyword('end\|after'), 'pattern_match_clauses': s:keyword('after')},
\'i': {'aligned_clauses': s:keyword('end\|else'), 'pattern_match_clauses': never_match},
\'[': {'aligned_clauses': ']', 'pattern_match_clauses': never_match},
Expand Down
13 changes: 0 additions & 13 deletions bin/spawn_vim

This file was deleted.

2 changes: 1 addition & 1 deletion compiler/credo.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
endif

CompilerSet errorformat=%f:%l:\ %t:\ %m
CompilerSet errorformat=%f:%l:%c:\ %t:\ %m,%f:%l:\ %t:\ %m
CompilerSet makeprg=mix\ credo\ suggest\ --format=flycheck
9 changes: 7 additions & 2 deletions compiler/mix.vim
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,10 @@ if exists(":CompilerSet") != 2
command -nargs=* CompilerSet setlocal <args>
endif

CompilerSet errorformat=%A%t%*[^:]:\ %m,%C%f:%l:\ %m,%C%f:%l,%Z
CompilerSet makeprg=mix
CompilerSet makeprg=mix\ compile
CompilerSet errorformat=
\%Wwarning:\ %m,
\%C%f:%l,%Z,
\%E==\ Compilation\ error\ in\ file\ %f\ ==,
\%C**\ (%\\w%\\+)\ %f:%l:\ %m,%Z

Loading