Giter Club home page Giter Club logo

Comments (10)

prabirshrestha avatar prabirshrestha commented on June 18, 2024 1

@cvlmtg Thanks a lot for the PR.

Closing this issue, for the any related file asyncompletions we can now use https://github.com/prabirshrestha/asyncomplete-file.vim to continue discussion there.

from asyncomplete.vim.

prabirshrestha avatar prabirshrestha commented on June 18, 2024

This is on my todo list. For now you can use vim file completion using <c-x><c-f> with asyncomplete.

from asyncomplete.vim.

prabirshrestha avatar prabirshrestha commented on June 18, 2024

created an empty repository for now https://github.com/prabirshrestha/asyncomplete-file.vim

from asyncomplete.vim.

roxma avatar roxma commented on June 18, 2024

I just noticed vim's path option recently, it's usefule to integrate it into the completion too.

NCM currently uses these base directories for path completion:

  • directory of current buffer expand('%:p')
  • directory of current working directory getcwd()
  • root directory, which is / on linux system.
  • directories listed in path option

from asyncomplete.vim.

prabirshrestha avatar prabirshrestha commented on June 18, 2024

Given that we now have LSP support for both vim and neovim with autocomplete that works for asyncomplete, NCM and deoplete might be better to write a lang server instead. This way one could write in any language they want and actually be used by in any plugin. Here is a language server I wrote for typescript https://github.com/prabirshrestha/typescript-language-server. It is very easy to write one.

from asyncomplete.vim.

cvlmtg avatar cvlmtg commented on June 18, 2024

Hi, i've hacked together a file completion source. I'm a total vimscript noob, so this code is probably inefficient or event totally wrong (and it's not async), but it seems to do its work, so I'm sharing it here with the hope it might be useful to someone else, until a proper plugin is written by someone more experienced 😃

the path is always relative to the file being edited and there are no configurations or other tricks (like maybe using git ls-files in a git repo) but this is left as an exercise to the reader

function! s:filename_map(prefix, file) abort
  let l:abbr = fnamemodify(a:file, ':t')
  let l:word = a:prefix . l:abbr

  return {
        \ 'menu': '[path]',
        \ 'word': l:word,
        \ 'abbr': l:abbr,
        \ 'icase': 1,
        \ 'dup': 0
        \ }
endfunction

function! s:filename_completor(opt, ctx) abort
  let l:bufnr = a:ctx['bufnr']
  let l:typed = a:ctx['typed']
  let l:col   = a:ctx['col']

  let l:kw    = matchstr(l:typed, '<\@<!\.\{0,2}/.*$')
  let l:kwlen = len(l:kw)

  if l:kwlen < 1
    return
  endif

  if l:kw !~ '^/'
    let l:cwd = expand('#' . l:bufnr . ':p:h') . '/' . l:kw
  else
    let l:cwd = l:kw
  endif

  let l:glob = fnamemodify(l:cwd, ':t') . '*'
  let l:cwd  = fnamemodify(l:cwd, ':p:h')
  let l:pre  = fnamemodify(l:kw, ':h')

  if l:pre !~ '/$'
    let l:pre = l:pre . '/'
  endif

  let l:cwdlen   = strlen(l:cwd)
  let l:startcol = l:col - l:kwlen
  let l:files    = split(globpath(l:cwd, l:glob), '\n')
  let l:matches  = map(l:files, {key, val -> s:filename_map(l:pre, val)})

  call asyncomplete#complete(a:opt['name'], a:ctx, l:startcol, l:matches)
endfunction

call asyncomplete#register_source({
      \ 'name': 'filenam',
      \ 'whitelist': ['*'],
      \ 'priority': 10,
      \ 'completor': function('s:filename_completor'),
      \ })

from asyncomplete.vim.

prabirshrestha avatar prabirshrestha commented on June 18, 2024

@cvlmtg could you send a PR to https://github.com/prabirshrestha/asyncomplete-file.vim?

from asyncomplete.vim.

cvlmtg avatar cvlmtg commented on June 18, 2024

@prabirshrestha if you think this code is good enough I will

from asyncomplete.vim.

cvlmtg avatar cvlmtg commented on June 18, 2024

(btw the fork button is disabled. maybe you should push a commit first)

and... since I've never written a vim plugin before, a minimal empty template would help me a lot!

from asyncomplete.vim.

prabirshrestha avatar prabirshrestha commented on June 18, 2024

@cvlmtg send a PR and we can iterate there. Easier to comment in a PR. I pushed the initial commit you should be able to fork now.

from asyncomplete.vim.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.