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

Automatically add use statement #234

Closed
longrunningprocess opened this issue Jan 9, 2017 · 28 comments
Closed

Automatically add use statement #234

longrunningprocess opened this issue Jan 9, 2017 · 28 comments
Labels

Comments

@longrunningprocess
Copy link

When adding a class in the code, it would be great if the use statement was automatically written into the top of the file. Thanks for considering!

@felixfbecker
Copy link
Owner

I would love to have this, and it is not even hard that hard to implement.

@longrunningprocess
Copy link
Author

Glad to hear it wouldn't be difficult. I hope you'll forgive me for not contributing beyond the request 0:-)

@arturolinares
Copy link

👍

@felixfbecker
Copy link
Owner

Please don't +1 issues. It clutters the thread without adding value to the discussion and spams maintainers with notifications. Use GitHub reactions to upvote features.
image

@sugarmaster
Copy link

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

@felixfbecker Is there any protocol I can use?

@felixfbecker
Copy link
Owner

yeah, you can return additionalTextEdits from textDocument/completion

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

@felixfbecker How to get the positon of the first php start tag after the namespace definition? I don't have any (serious) idea. Should I set a variable in PhpDocument with the place to enter while parsing the thing?

@felixfbecker
Copy link
Owner

Theres a getClosestNode() in helpers which you can use to find the closest namespace Node, then you can easily get the first statement inside it.

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

Beautiful. I thought I need to implement this functionality myself.

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

Ah, there is a bug. getClosestNode will return void instead of null. Short pull request comes...

@felixfbecker
Copy link
Owner

Functions that return nothing return null.

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

This does not. That's the bug.

@felixfbecker
Copy link
Owner

felixfbecker commented Apr 10, 2017

function foo() {
}

$f = foo();

var_dump($f); // NULL

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

It's better to return that from the code, isn't it?

@felixfbecker
Copy link
Owner

It makes not difference

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

okay.

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

How is the PHP start tag called in php-parser? I'd looked in the files, but I couldn't find anything related.
Node\Stmt\Namespace_ is for Namespaces
??? is for the PHP start tag?

@felixfbecker
Copy link
Owner

There is no PHP start tag, only InlineHtml

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

But I can't rely on that, can I? I need to find the first "save" location where I can insert the use statement. At the moment I'm searching for a fallback when there is no namespace statement.

@staabm
Copy link
Contributor

staabm commented Apr 10, 2017

before the first class definition?

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

yes, and maybe behind the declare node(implemented). But I need a fallback.

@felixfbecker
Copy link
Owner

The fallback would just be at the root? Which is the $stmts array

@jens1o
Copy link
Contributor

jens1o commented Apr 10, 2017

But then it may be possible to get a use statement right after inline html?

@thoresuenert
Copy link

@jens1o how is it going?
do you need help?
Where to contribute?

@jens1o
Copy link
Contributor

jens1o commented May 8, 2017

Hmm, I didn't continued, since I have school again and I'm writing lots of exams... So yeah, I need some help. In the evening, I'll push my tries, maybe you can contribute..

@Munsio
Copy link

Munsio commented Jul 6, 2017

@jens1o where can we find the branch?

@jens1o
Copy link
Contributor

jens1o commented Jul 6, 2017

On my old pc. Dammit. I'm again in exam phase, I'm sorry. Even though, I would have to write it again because of the new parser. Before I can do that, I would like to push forward foreach support.

@longrunningprocess longrunningprocess closed this as not planned Won't fix, can't repro, duplicate, stale Dec 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants