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

[READY] Java support using jdt.ls #857

Merged
merged 51 commits into from
Jan 22, 2018

Commits on Jan 21, 2018

  1. Basic framework for Java Language Server connection

    Build the jdt.ls server in build.py
    Start the server
    Connect to the server using stdio
    Send the initialise request
    Basic support for completions (prototype)
    Update the file contents in the server
    Use a workspace dir for each invocation.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    abea266 View commit details
    Browse the repository at this point in the history
  2. Support for basic completions

    Apply textEdits in completion items
    
    Language server protocol requires that the client can apply textEdits,
    rather than just simple text. This is not an optional feature, but ycmd
    clients do not have this ability.
    
    The protocol, however, restricts that the edit must include the original
    requested completion position, so we can perform some simple text
    manipulation to apply the edit to the current line and determine the
    completion start column based on that.
    
    In particualr, the jdt.ls server returns textEdits that replace the
    entered text for import completions, which is one of the most useful
    completions.
    
    TODO: this doesn't currently work where there is a mixture of start
    positions.
    
    We also include experimental support for "additionalTextEdits" which
    allow automatic insertion of, e.g.,  import statements when selecting
    completion items. These are sent on the completion response as an
    additional completer data item called 'fixits'. The client applies the
    same logic as a standard FixIt once the selected completion item is
    inserted.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    b32aa86 View commit details
    Browse the repository at this point in the history
  3. Add a long-polling endpoint for asyncronous message delivery

    A new API endpoint '/receive_messages' has been added which allows the
    server to return messages for display to the user at arbitrary times.
    
    Previously it was only possible for the ycmd server to communicate and
    action or update on receipt of a synchronous request from the client.
    
    However, the language server protocol inherently supports asynchronous
    message delivery, and it is necessary to provide some of these message
    to clients.
    
    In particular, the jdt.ls server takes a very long time to start up and
    provides some "status" information. We use a "display message" response
    to inform the client to show the user a progress update.
    
    Fully asyncronous delivery of diagnostics.
    
    Implement a proper ready handler (precursor to adding tests)
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    0f64bbd View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    72cb431 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    53b7592 View commit details
    Browse the repository at this point in the history
  6. Add subcommands: FixIt, RefactorRename, GoToReferences, GetDoc, GetType

    Support for CodeActions via FixIts
    Support for RefactorRename
    Support for GoToReferences
    Add GoTo and GoToDeclaration aliases for GoToDefinition
    Implement GetDoc and GetType
    
    GetType is removed from language_server_completer.py since a server is
    allowed to return anything upon textDocument/hover request.
    
    GetType and GetDoc are Implemented in java_completer.py with a server
    specific modifications to the content of the response to the
    textDocument/hover request.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    5f54b51 View commit details
    Browse the repository at this point in the history
  7. Finalize language server protocol implementation

    Use url2pathname and pathname2url from urllib to convert URI to filepath
    and vice versa in a portable way.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    cc67757 View commit details
    Browse the repository at this point in the history
  8. Add tests and fix issues

    Initial test framework and StopServer subcommand
    
    Implement StopServer subcommand so the server is start/stopped by the
    tests. Note: This exposes a number of bugs in the shutdown handling.
    
    Adds basic eclipse and maven test projects
    Adds basic tests for completion
    Add timeouts appropriate for the test environment (Travis)
    Test for snippets with completions
    Tests for GetType, GetDoc, GoToReferences, RefactorRename, diagnostics
    
    For now the diagnostics tests use os.path.normpath. This doesn't work,
    but it is required due to extra slashes on filepaths returned by
    url2filepath
    
    Make fixit responses stable across files, for the tests
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    2c69c51 View commit details
    Browse the repository at this point in the history
  9. Don't _require_ that someone is listening to the message poll to hand…

    …le the messages we care about
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    565a979 View commit details
    Browse the repository at this point in the history
  10. Initialise asyncronously to avoid blocking when the server takes ages…

    … to start or fails to start
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    09fca85 View commit details
    Browse the repository at this point in the history
  11. Return diagnostics for all files asynchronously _and_ on parse request.

    This changes the diagnostics delivery so that we return the diagnostics
    to the client in the same way that the language server does, i.e.
    per-file. The client then fans them out or does whatever makes sense for
    the client.
    
    In order to be relatively compatible with other clients, we also return
    diagnostics on the file-ready-to-parse event, even though they might be
    out of date wrt the code. The client is responsible for ignoring these
    diagnostics when it handles the asynchronously delivered ones.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    ad36c3f View commit details
    Browse the repository at this point in the history
  12. Properly shut down the language server

    Close server standard output on close
    Close all the sockets when the read loop exits
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    03b750f View commit details
    Browse the repository at this point in the history
  13. Improve handling of the workspace directory

    The workspace dir can be legitimately empty
    Use a tmpdir for the workspace, as the tests can end up with multiple
    instances using the same one which leads to race conditions
    Create new workspace on server restart
    Delete the project, implementing the log handler to populate and put in
    ycmd's log
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    d2434a1 View commit details
    Browse the repository at this point in the history
  14. Actually send modify requests, as these should be better for lifecycl…

    …e management - we still replace the entire file
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    abd04b0 View commit details
    Browse the repository at this point in the history
  15. Improve code clarity and organisation

    Rename legacy-named 'server' to 'connection'
    General code tidy and organisation.
    Document interface.
    Consistent use (or not) of _ prefix.
    Take methods out of class that don't rely on self.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    8511daf View commit details
    Browse the repository at this point in the history
  16. Improve workspace handling and test stability

    Run the startup/shutdown tests in clean directory to prevent java completer from scanning itself and timing out
    Reinstate clean workspace, but provide option for reuse
    Don't create unused and uncleaned temporary directories on Reset
    Use the project directory calculated by the implementation
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    9ddcd12 View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    435bd5c View commit details
    Browse the repository at this point in the history
  18. More tests and test fixes

    Add missing test dir
    Fix subcommands offsets
    fix diagnostics test
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    5fddce3 View commit details
    Browse the repository at this point in the history
  19. Correctly handle textEdit completions

    We now no longer support completions with newlines.
    
    We now correctly return completions where the entry is a TextEdit and
    multiple completions have different start columns.
    
    We do this super inefficiently by attempting to normalise the TextEdits
    into insertion_texts with the same start_codepoint. This is necessary
    particularly due to the way that eclipse returns import completions for
    packages.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    f377e35 View commit details
    Browse the repository at this point in the history
  20. Configuration menu
    Copy the full SHA
    b57e72d View commit details
    Browse the repository at this point in the history
  21. Configuration menu
    Copy the full SHA
    a4ba2e0 View commit details
    Browse the repository at this point in the history
  22. Configuration menu
    Copy the full SHA
    ac930d2 View commit details
    Browse the repository at this point in the history
  23. Tests for FixIts

    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    5c028f9 View commit details
    Browse the repository at this point in the history
  24. Configuration menu
    Copy the full SHA
    8e50a9d View commit details
    Browse the repository at this point in the history
  25. Configuration menu
    Copy the full SHA
    041eab4 View commit details
    Browse the repository at this point in the history
  26. Configuration menu
    Copy the full SHA
    6d9bce0 View commit details
    Browse the repository at this point in the history
  27. Code style and clarity

    Tidy some FIXME/TODO
    Fix 80 chars in README.md
    Remove unused logging
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    c346d0f View commit details
    Browse the repository at this point in the history
  28. Configuration menu
    Copy the full SHA
    6b1f990 View commit details
    Browse the repository at this point in the history
  29. More tests and fixes

    Add gradle test project
    Move server management tests to their own file. Add gradle test.
    GoTo tests
    Working tests for GoTo, GoToDeclaration and GoToDefinition.
    A test for unicode characters is missing.
    Fix KeyError bubbling to users when jdt.ls returns dodgy defnition
    Unicode tests, and fixes
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    76edefe View commit details
    Browse the repository at this point in the history
  30. Configuration menu
    Copy the full SHA
    3171369 View commit details
    Browse the repository at this point in the history
  31. Configuration menu
    Copy the full SHA
    e159015 View commit details
    Browse the repository at this point in the history
  32. Fix printing of raw messages on py2 and py3

    Print the bytes of the messages rather than throw an exception.
    Ref: https://www.simonmweber.com/2014/11/24/python-logging-traps.html
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    cfed48d View commit details
    Browse the repository at this point in the history
  33. If we receive a parse request before the server is initialised, queue…

    … it to ensure the server has latest file content
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    f663862 View commit details
    Browse the repository at this point in the history
  34. Configuration menu
    Copy the full SHA
    68aa585 View commit details
    Browse the repository at this point in the history
  35. Configuration menu
    Copy the full SHA
    df391a5 View commit details
    Browse the repository at this point in the history
  36. Configuration menu
    Copy the full SHA
    76f413b View commit details
    Browse the repository at this point in the history
  37. Configuration menu
    Copy the full SHA
    60c849e View commit details
    Browse the repository at this point in the history
  38. Include the text of the line at the reference site, as the _greatly_ …

    …improves the utility of the GoToReferences command
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    7eb7b4f View commit details
    Browse the repository at this point in the history
  39. Configuration menu
    Copy the full SHA
    1004f63 View commit details
    Browse the repository at this point in the history
  40. Configuration menu
    Copy the full SHA
    01f84e1 View commit details
    Browse the repository at this point in the history
  41. Refactoring and fixes after review

    Typos and style changes
    Move mappings to lsapi
    Don't include an extra newline, as this is not strictly in the protocol
    Use the generic implementation of WaitUntilCompleterServerReady
    Fix exception when running debug info and server not running
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    689f396 View commit details
    Browse the repository at this point in the history
  42. Improve the API and stability for shutdown

    Close the connection in the handler thread to avoid race condition. Test
    failed shutdown
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    072cfd1 View commit details
    Browse the repository at this point in the history
  43. Improve test coverage

    Increase the timeout for the shutdown tests for our CI environment
    Test receive_messages handler without completer support
    Fix project detection tests
    Additional tests for things we can't easily test in the CI with real server
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    8c2f192 View commit details
    Browse the repository at this point in the history
  44. More refactoring and fixes after review

    Rename lsapi to language_server_protocol
    Tidy build.py
    Better names for subcommand handlers
    Use snake case for variables
    Clarify the threading setup for the language server connection
    Despatch -> Dispatch
    Better name for _RefreshFiles
    Refactor large completion item methods
    Update API documentation for long poll, and fix the nonblocking pending messages handler
    rename textEdit to text_edit for coding style
    Tracing shutdown to help post mortem diagnostics
    Update copyright year
    Move all exceptions to he top of the module
    Public or API methods are not private. All other methods are private
    More refactoring of completion item resolution code
    Compute whether or not to resolve completions statically
    Remove bare except
    Mention jdt.ls in the ycmd README
    Fix up comment in example client
    Typos and stylistic changes
    Log when we get errors
    Don't include the optional header
    Remove import hack laziness for TemporaryClangTestDir
    Remove extraneous parentheses
    More trivial code tidy
    Use correct GoTo response and errors
    Don't convert the id to string more than once
    Clarify client capabilitites
    Add INFORMATION and HINT to the ycmd API rather than mapping it
    Use 'Unkonwn type' like clang completer
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    dd6799d View commit details
    Browse the repository at this point in the history
  45. Further improvements to shutdown handling

    Join the dispatch thread after closing sockets
    Don't forcefully kill the server as this causes issues on Windows
    Ensure that we don't start (and not stop) a JediHTTP instance in shutdown tests
    Use SharedYcmd for handler tests
    Properly namespace server management tests
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    24853c5 View commit details
    Browse the repository at this point in the history
  46. Configuration menu
    Copy the full SHA
    1f8adc4 View commit details
    Browse the repository at this point in the history
  47. Update to jdt.ls v0.11.0 and complete coverage tests

    This required a number of things, not least implementing a proper model
    of the server file state and using that to reduce the number of
    didClose/didChange events to send. This fixes the interpretation of the
    file_data: only modified buffers are included, so we must read the
    contents of non-modified (but open) buffers from disk.
    
    Finally, we also move to using binary packages to improve the build
    times, and tidy up the third party area.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    79d8544 View commit details
    Browse the repository at this point in the history
  48. Configuration menu
    Copy the full SHA
    c42d5e8 View commit details
    Browse the repository at this point in the history
  49. Ensure that the message poll doesn't fail on first request

    Since we start the server on the FileReadyToParse event, the client
    might send the initial poll request before we've attempted to start the
    server. So in that case we wait at least one poll interval for the
    initialize sequence to complete before starting the poll loop.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    9b08789 View commit details
    Browse the repository at this point in the history
  50. Use UTF16 code unit offsets not codepoint offsets

    Per the language server protocol, we need to count UTF16 code units.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    feba227 View commit details
    Browse the repository at this point in the history
  51. Only resolve up to 100 items

    On larger projects and slower systems, resolving many items can be very
    costly, and not really all that useful.
    puremourning committed Jan 21, 2018
    Configuration menu
    Copy the full SHA
    e03836f View commit details
    Browse the repository at this point in the history