Skip to content

Completion #9

Closed
Closed

Description

@felixfbecker

Should suggest:

  • global symbols (classes, interfaces, traits, functions)
  • local variables
  • local parameters
  • variables imported with use
  • not the variables outside of the function scope
  • properties and methods of classes if the cursor is behind a ->
    • it should resolve the variable to a class type and get the members
  • namespaces and classes when the cursor is inside a use statement
  • built-in PHP functions, classes and globals
    • how to get them? Is there a machine-parseble version of the docs?

It should:

  • follow PSR autoloading rules defined in composer.json
  • parse docblocks for type annotations of parameters and properties

Activity

  1. lgabeskiria commented on Sep 4, 2016

    @lgabeskiria
    Contributor
  2. felixfbecker commented on Sep 6, 2016

    @felixfbecker
    OwnerAuthor

    Thanks for the hint!

  3. mniewrzal commented on Sep 6, 2016

    @mniewrzal
    Contributor

    For more advanced completion features language server needs to index files from project. For now it looks that whole process of indexing is not standardized (microsoft/language-server-protocol#54)

  4. changed the title [-]provideCompletion[/-] [+]Completion[/+] on Sep 9, 2016
  5. kaloyan-raev commented on Sep 13, 2016

    @kaloyan-raev
    Contributor
  6. felixfbecker commented on Sep 13, 2016

    @felixfbecker
    OwnerAuthor

    I think relying on the PHPStorm stubs is the better way to go.

    As for the indexing, here is what I have in my head:

    • Upon initialization, parse the stub files
    • Upon a completion request
      • at the start of a line (no node in front of it)
        • check if it has been used in the file, try to load it using the autoloader if yes
        • read the directory (which is equivalent to the current namespace). we can quickly provide the list of files as classes, then resolve additional details with the completionItem/resolve request by parsing it. folders can be provided as namespaces the same way.
        • check if it is in the globally parsed files (composer.json files property and stubs)
      • with a namespace name in front it, do the above steps in the typed namespace
      • with a class in front of it, find the file with the autoloader and parse it, then provide completion
      • with a variable in front of it, find the definiton (basically what definitionRequest will do), then find out its type (assignment or parameter type hint / docblock. Need some recursive logic here to resolve assignments). If the resolved type is a class, find the file with the autoloader and parse it, then provide completion.
  7. felixfbecker commented on Sep 13, 2016

    @felixfbecker
    OwnerAuthor

    https://github.com/JetBrains/phpstorm-stubs is licensed under Apache 2, while the language server is ISC. Does anyone know if we can use it? Are they compatible? Afaik Apache 2 is more restrictive

  8. kaloyan-raev commented on Sep 13, 2016

    @kaloyan-raev
    Contributor

    Do you plan redistributing the stub files with the language server? If yes, then looking at the license compatibility would make sense.

    Another approach is to download the stub files on demand, i.e. before parsing them during the initialize phase. This way the language server is not tightly coupled to the stub files. Users may even configure the language server to download stub files from a different location. This approach should not qualify as "redistribution" and I don't see any license issue.

  9. felixfbecker commented on Sep 13, 2016

    @felixfbecker
    OwnerAuthor

    I was planning to add them as dependency with composer:

        "require": {
            "JetBrains/phpstorm-stubs": "dev-master"
        },
        "repositories": [
            {
                "type": "package",
                "package": {
                    "name": "JetBrains/phpstorm-stubs",
                    "version": "dev-master",
                    "dist": {
                        "url": "https://github.com/JetBrains/phpstorm-stubs/archive/master.zip",
                        "type": "zip"
                    },
                    "source": {
                        "url": "https://github.com/JetBrains/phpstorm-stubs",
                        "type": "git",
                        "reference": "master"
                    }
                }
            }
        ],

    downloading on demand would be an option of course, that would put the burden on the user. The extension would have to make it easy for the user to download them and then send the location to the language server. Why can't they just release as ISC/MIT 🙄

  10. kaloyan-raev commented on Sep 13, 2016

    @kaloyan-raev
    Contributor

    I guess you can open an issue to the phpstorm-stubs project and ask to change the license to MIT/ISC.

    However, I have read the 4. Redistribution section of the Apache 2.0 license and I don't see any license compatibility issue to distribute the stubs as you have described above.

    Is there any particular clause that worries you?

  11. felixfbecker commented on Sep 13, 2016

    @felixfbecker
    OwnerAuthor

    No, I just wanted to be sure. When we add it as dependency, the license notice will be included in the subfolder, so I guess it should be fine?

    By the way: I just did a diff between HvyIndustries/crane-php-stubs and JetBrains/phpstorm-stubs and they are basically the same. Besides changes that were not merged from the upstream and some renames, the files are almost identical and it looks like crane's stubs are based on JetBrain's. Which would mean he copied the JetBrains stubs, removed the README and LICENSE, removed the PHPStorm specific files, and published it in a fresh commit as "crane php stubs". That would be an illegal copyright infringement and a violation of the license terms, which states that the license must be included in all copies.

    That is exactly what I do not want to do. Give credit where credit is due.

  12. kaloyan-raev commented on Sep 13, 2016

    @kaloyan-raev
    Contributor

    I did not notice that. I agree with you.

  13. felixfbecker commented on Sep 13, 2016

    @felixfbecker
    OwnerAuthor

    Maybe I'm wrong and the diff just happens to be similar because it includes the same documentation and signatures. I don't want to falsely accuse anyone here, and it is none of my business, but for this language server I think we shouldn't maintain our own stubs and it's best to include some open source option (without breaking any license).

  14. lgabeskiria commented on Sep 13, 2016

    @lgabeskiria
    Contributor

    how about including completion for [global] keyword?

  15. mniewrzal commented on Sep 13, 2016

    @mniewrzal
    Contributor

    I'm experimenting with keywords completion. I prepare simplest possible implementation https://github.com/mniewrzal/php-language-server/tree/keyword_completion. There are two problems. First is that internal PHP support in VS Code also has now keywords completion (results are doubled). But its not very important from language server point of view. Second is microsoft/vscode#11876 and I'm wating for response from Code team.

  16. felixfbecker commented on Oct 23, 2016

    @felixfbecker
    OwnerAuthor

    @Gert-dev thanks for reaching out! This language server is intended to be usable by any IDE as it uses the open language server protocol, which is being implemented by many IDEs. That means if Atom had a LSP client, it could consume it too. The server already has a simple indexer, it just isn't used to provide completion yet, only "go to definition", symbol search, "find all references", hover and parse errors. I am very open to joining efforts, and am particulary interested in how you leveraged the PHP parser to provide completion. Since your codebase is quite large and to not clutter this issue, would you jump on Gitter and explain a bit of your work?

  17. self-assigned this
    on Nov 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions