Skip to content
This repository has been archived by the owner on Jul 31, 2018. It is now read-only.

[RFC] updates cwd with the g:phpactorInitialCwd #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

[RFC] updates cwd with the g:phpactorInitialCwd #2

wants to merge 1 commit into from

Conversation

cmizzi
Copy link

@cmizzi cmizzi commented Oct 6, 2017

As PHPActor now handles a --working-dir option, we have to specify the initial working directory instead of Neovim CWD

As PHPActor now handles a `--working-dir` option, we have to specify the initial working directory instead of Neovim CWD
@roxma
Copy link
Owner

roxma commented Oct 7, 2017

#1 (comment)

If this PR get merged, the user change directory to another project with nvim's :cd dir, phpactor won't work?

@cmizzi
Copy link
Author

cmizzi commented Oct 10, 2017

Hum, the cwd is only took when the plugin is created. It is not updated on each buffer change until have this kind of functions :

" Update PHPActor cwd each time a new buffer is accessed
function! UpdatePHPActorPath()
	" Change working dir to the current file
	cd %:p:h

	" Set 'gitdir' to be the folder containing .git
	let gitdir = system("git rev-parse --show-toplevel")

	" See if the command output starts with 'fatal' (if it does, not in a git repo)
	if empty(matchstr(gitdir, '^fatal:.*'))
		let g:phpactorInitialCwd = gitdir
	endif
endfunction

autocmd BufEnter *.php call UpdatePHPActorPath()

The cwd will be same during nvim instance until the variable is voluntary changed (cwd is used once)

@roxma
Copy link
Owner

roxma commented Oct 10, 2017

The cd command inside UpdatePHPActorPath doesn't look good to me.

If cd is executed automatically, plugins like FZF, ag will be affected.

I would rather automatically use the directory of current file for invoking phpactor.

@cmizzi
Copy link
Author

cmizzi commented Oct 10, 2017

This function is not used by the plugin. This is what I do in order to work on multiple projects into a single Vim instance. By default, without this function, the get:phpactorInitialCwd is took from instance creation and is not updated on buffer change.

@roxma
Copy link
Owner

roxma commented Oct 10, 2017

OK

My point is, it doesn't look like a good idea to accept g:phpactorInitialCwd as phpactor/plugin does

Perhaps @dantleech could give some advice // phpactor/phpactor@65b9793#diff-b96c23eeb9efb3d1ce52e97eaf5019b6R11

@cmizzi
Copy link
Author

cmizzi commented Oct 10, 2017

phpactor assumes that when the instance creation is based on the instance working dir. I'm not really happy with that but as the phpactor binary can handle a --working-dir argument, it's not really a bad thing as it can be modified on the fly.

@roxma
Copy link
Owner

roxma commented Oct 10, 2017

it's not really a bad thing as it can be modified on the fly.

Yeah. But current PR adds overhead to new users, because they may need to add vimrc to change g:phpactorInitialCwd, while current version doesn't require them to do so.

It is quite straightforward to simply use the value of getcwd() instead. Unless you explicitly configure it not to.

@dantleech
Copy link
Contributor

dantleech commented Oct 10, 2017

I think it should be fine to pass the g:phpactorInitialCwd ?

Although since the introduction of RPC, we could equally delegate the call to the Phpactor VIM plugin:

    let suggestions = phpactor#rpc("complete", { "offset": offset, "source": source})

This would also have the additional benefit of any errors being echoed to the status line instead of silently failing.

@roxma
Copy link
Owner

roxma commented Oct 10, 2017

Although since the introduction of RPC, we could equally delegate the call to the Phpactor VIM plugin:

The whole point of the existance of this plugin is for async completion support, which prevents blocking the ui when running phpactor (vimscript is single-threaded). Though performance is not an issue for phpactor.

@dantleech
Copy link
Contributor

dantleech commented Oct 10, 2017

Though performance is not an issue for phpactor.

It can be in some cases (as parsing / reflection is done in real time, with huge classes it's can be a slight issue)

But current PR adds overhead to new users, because they may need to add vimrc to change g:phpactorInitialCwd

Hmm, only if this plugin is registered before the phpactor plugin? But maybe that's non-obvious.

@cmizzi
Copy link
Author

cmizzi commented Oct 10, 2017

I think it's important that the omnifunc and this plugin return same result. If this plugin handles getcwd (so :cd will change the current call path), phpactor needs to do the same thing. If I press <C-o> or simply use the smart-completion, it would be greater if results are the same ?

@roxma
Copy link
Owner

roxma commented Oct 17, 2017

I understand.

But I still don't like current behavior of g:phpactorInitialCwd.

I think current behavior is better than that.

I'll keep this open, wait for more comments and see how it goes

@roxma roxma changed the title updates cwd with the g:phpactorInitialCwd [RFC] updates cwd with the g:phpactorInitialCwd Oct 17, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants