onivim / oni

Oni: Modern Modal Editing - powered by Neovim
https://www.onivim.io
MIT License
11.35k stars 299 forks source link

'/' is ignored during completion #678

Closed hoschi closed 6 years ago

hoschi commented 7 years ago

When I want to import something from a module and type this (cursor is |):

import * from '.|'

I see in devtools console:

Get completions: current line import * from '.'

which returns all global JS modules, which is ok. When I add a '/' and have now:

import * from './|'

I want to see all modules in the current folder, but I get no completion candidates at all. The console doesn't even log a request for completions. I must add an additional letter to get the completions, which then work:

import * from './|p'

Which logs:

Get completions: current line import * from './p

The problem is probably an escaping issue?

bryphe commented 7 years ago

Ah yes, I hit this too, it is annoying!

I believe the problem is here in oni/vim/core/oni-plugin-typescript/src/index.ts:

    const getCompletions = (textDocumentPosition: Oni.EventContext) => {
        if (textDocumentPosition.column <= 1) {
            return Promise.resolve({
                completions: [],
            })
        }

        const currentLine = lastBuffer[textDocumentPosition.line - 1]
        let col = textDocumentPosition.column - 2
        let currentPrefix = ""

        while (col >= 0) {
            const currentCharacter = currentLine[col]

            if (!currentCharacter.match(/[_a-z]/i)) {
                break
            }

            currentPrefix = currentCharacter + currentPrefix
            col--
        }

        const basePos = col

        if (currentPrefix.length === 0 && currentLine[basePos] !== ".") {
            return Promise.resolve({
                base: currentPrefix,
                completions: [],
            })
        }

This logic decides where we 'ask' for completions from, and what the prefix is. Right now, because of the regex - /[_a-z]/i), it's only matching letters + underscore, and ideally it would match some additional characters as above.

Expanding this to handle some of those cases, or be more generalized, would be very helpful!

CrossR commented 6 years ago

Hopefully this will be fixed for you with #861, which was just merged in.

bryphe commented 6 years ago

Thanks @CrossR !