You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Omni completion open fzf list to choose a class #780
It appears that it might have nothing to do with fzf.
It doesn't not append with all classes (not figure out why yet).
But it works pretty well with Exception, to reproduce I Type:
newExcpetion<>
And then <C-x><C-o> and <Enter> once I'm on the right line.
The first time, it's all fine.
The second time, the inputlist is opened.
If I understood correctly if the candidate is already imported null is returned, and it's the class_import which is given to the suggestion.
The suggestions are then returned to the vim plugin which store them inside g:_phpactorCompletionMeta.
Then on CompleteDone the function phpactor#_completeImportClass is executed and this code is executed:
Require an input from the user, which open the inputlist.
First of all, do you agree with this explanation ?
If yes, then what do you propose ?
It feels to me like the ScfClassCompletor and ImportClassHandler classes have evolved in different directions.
ScfClassCompletor seems to return null as class_import if the class doesn't have to be imported.
But it's not its responsibility to check that.
All it should do is generate a list of suggestions.
Then the ImportClassHandler will decide if the suggestion should be imported or not (it already does).
Thanks for the bug report, I can confirm this is an issue when importing an already imported class automatically.
ScfClassCompletor seems to return null as class_import if the class doesn't have to be imported.
But it's not its responsibility to check that.
Not sure tbh. The idea is that the handlers be as stupid as possible -- as there can be other RPC implementations, e.g. the language server completion extension -- although in this case the language server protocol would expect text edit(s) to be provided rather than "class_import" returned by the Phpactor RPC protocol.
The completion stuff does feel sometimes like it's crossing some boundaries.
If yes, then what do you propose ?
Maybe just check in the plugin to see if class_import has a value?
The idea is that the handlers be as stupid as possible
I didn't mean that the handler should do the checks, just that it will return a response if there is a problem (exception).
And that's the code-transform extension that will return an exception.
In case of a language server, I never implemented one but my guess is that it's the same thing.
A handler will translate a user request for the core, and the core response to the user.
Either way, the code-transform extension has the responsibility to handle the cases when the class is already imported or in the same namespace.
An empty "edit(s)" maybe.
Maybe just check in the plugin to see if class_import has a value?
Given what I've already said, I think it's hidden a symptom instead of treating the problem.
Plus it's coupling the vim plugin with the completor behaviour.
Given what I've already said, I think it's hidden a symptom instead of treating the problem.
Plus it's coupling the vim plugin with the completor behaviour.
Hmm ... the Suggestion always serializes class_import key (even on non-class completions). The behavior is that if it is not null, then the given FQN should be imported. Or maybe I missed something? Not to say it couldn't be better, but it works as designed as far as I can tell.
Ok, so you are saying that class_import must be null so that a class is not imported when completed something that is not a class ?
Then I would say that we should just change:
So that we try to import only on class completion.
I don't mean to criticize or anything, just try to get the best of this wonderful tool :)
And I think we should really kept the completor as simple as possible, It returns suggestions for a given "word" and that's it.
Am I missing a scenario where filling the class_import with the FQN even for classes that doesn't need to be imported will cause an issue ?
Given that we adapt the vim plugin of course, and maybe other implementation I'm not aware of.
I think what I saying is that it _is_ null and set by default. The serialized Suggestion always has that key, so not sure what's going on tbh :)
It's meant to be imperative, as said. If it's set, it should be imported.
That said, I think I'm confused... and on the road currently.
On 14 June 2019 18:22:43 BST, ely ***@***.***> wrote:
Ok, so you are saying that `class_import` must be null so that a class
is not imported when completed something that is not a class ?
Then I would say that we should just change:
https://github.com/phpactor/phpactor/blob/6b1d22e903dde0e61cf1c8b683bec5cc9252dcfb/plugin/phpactor.vim#L133
By
```vim
if 'class' != get(suggestion, 'type', 'whatever')
```
So that we try to import only on class completion.
I don't mean to criticize or anything, just try to get the best of this
wonderful tool :)
And I think we should really kept the completor as simple as possible,
It returns suggestions for a given "word" and that's it.
Am I missing a scenario where filling the `class_import` with the FQN
even for classes that doesn't need to be imported will cause an issue ?
Given that we adapt the vim plugin of course, and maybe other
implementation I'm not aware of.
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
So if I understand correctly, it's a design choice to break the SRP in the Suggestion class.
Which force to also break the SRP in every completor since they must be aware of when a class should be imported or not.
In this case that's indeed the Vim plugin that contains the bug, it shouldn't check that the suggestion have a key class_import but that this key is not empty.
Since like you said, the key is always present.
I will provide a PR in that sense, but I still think that we should change this behaviour at some point.
I'm ready to implement it when you want :)
Activity
camilledejoye commentedon Jun 13, 2019
It appears that it might have nothing to do with fzf.
It doesn't not append with all classes (not figure out why yet).
But it works pretty well with
Exception, to reproduce I Type:And then
<C-x><C-o>and<Enter>once I'm on the right line.The first time, it's all fine.
The second time, the inputlist is opened.
I think the problem came all the way from here:
https://github.com/phpactor/completion/blob/cc1c4c8efedda9a6e856c5df443bb8aadc9c741f/lib/Bridge/TolerantParser/SourceCodeFilesystem/ScfClassCompletor.php#L98-L103
If I understood correctly if the candidate is already imported
nullis returned, and it's theclass_importwhich is given to the suggestion.The suggestions are then returned to the vim plugin which store them inside
g:_phpactorCompletionMeta.Then on
CompleteDonethe functionphpactor#_completeImportClassis executed and this code is executed:phpactor/plugin/phpactor.vim
Lines 134 to 139 in 6b1d22e
The
suggestion['class_import']is null, soqualified_nameis null to and send to the handler.Where finally:
phpactor/lib/Extension/CodeTransformExtra/Rpc/ImportClassHandler.php
Lines 76 to 97 in 6b1d22e
Require an input from the user, which open the inputlist.
First of all, do you agree with this explanation ?
If yes, then what do you propose ?
It feels to me like the
ScfClassCompletorandImportClassHandlerclasses have evolved in different directions.ScfClassCompletorseems to returnnullasclass_importif the class doesn't have to be imported.But it's not its responsibility to check that.
All it should do is generate a list of suggestions.
Then the
ImportClassHandlerwill decide if the suggestion should be imported or not (it already does).dantleech commentedon Jun 14, 2019
Thanks for the bug report, I can confirm this is an issue when importing an already imported class automatically.
Not sure tbh. The idea is that the handlers be as stupid as possible -- as there can be other RPC implementations, e.g. the language server completion extension -- although in this case the language server protocol would expect text edit(s) to be provided rather than "class_import" returned by the Phpactor RPC protocol.
The completion stuff does feel sometimes like it's crossing some boundaries.
Maybe just check in the plugin to see if
class_importhas a value?camilledejoye commentedon Jun 14, 2019
I didn't mean that the handler should do the checks, just that it will return a response if there is a problem (exception).
And that's the
code-transformextension that will return an exception.In case of a language server, I never implemented one but my guess is that it's the same thing.
A handler will translate a user request for the core, and the core response to the user.
Either way, the
code-transformextension has the responsibility to handle the cases when the class is already imported or in the same namespace.An empty "edit(s)" maybe.
Given what I've already said, I think it's hidden a symptom instead of treating the problem.
Plus it's coupling the vim plugin with the completor behaviour.
dantleech commentedon Jun 14, 2019
Hmm ... the Suggestion always serializes
class_importkey (even on non-class completions). The behavior is that if it is not null, then the given FQN should be imported. Or maybe I missed something? Not to say it couldn't be better, but it works as designed as far as I can tell.camilledejoye commentedon Jun 14, 2019
Ok, so you are saying that
class_importmust be null so that a class is not imported when completed something that is not a class ?Then I would say that we should just change:
phpactor/plugin/phpactor.vim
Line 133 in 6b1d22e
By
So that we try to import only on class completion.
I don't mean to criticize or anything, just try to get the best of this wonderful tool :)
And I think we should really kept the completor as simple as possible, It returns suggestions for a given "word" and that's it.
Am I missing a scenario where filling the
class_importwith the FQN even for classes that doesn't need to be imported will cause an issue ?Given that we adapt the vim plugin of course, and maybe other implementation I'm not aware of.
dantleech commentedon Jun 14, 2019
camilledejoye commentedon Jun 15, 2019
So if I understand correctly, it's a design choice to break the SRP in the
Suggestionclass.Which force to also break the SRP in every completor since they must be aware of when a class should be imported or not.
In this case that's indeed the Vim plugin that contains the bug, it shouldn't check that the suggestion have a key
class_importbut that this key is not empty.Since like you said, the key is always present.
I will provide a PR in that sense, but I still think that we should change this behaviour at some point.
I'm ready to implement it when you want :)