Skip to content
This repository has been archived by the owner on Sep 6, 2021. It is now read-only.

Language Server Protocol Support for Brackets #14606

Merged
merged 187 commits into from
Apr 2, 2019
Merged

Language Server Protocol Support for Brackets #14606

merged 187 commits into from
Apr 2, 2019

Conversation

jhasubhash
Copy link
Collaborator

@jhasubhash jhasubhash commented Dec 4, 2018

This covers the first cut of Language Server Protocol Support for Brackets.

Basic core implementation to:

  • Initiate/Stop a Language Server
  • Interact with Language Server
    • Completions
    • Signature Help
    • Diagnostics
    • Jump To Dec/Decl/Impl
    • Symbols
    • References
    • Synchronization Events (Text Document didOpen, didChange etc.)
    • Custom Request/Notification (so the developer can use commands not exposed in the initial implementation)
  • Bidirectional Request/Notification system for communication between Brackets and Language Server
  • Abstraction of LSP from Brackets (as far as possible)
  • Creation of Language Client that works as the handle to Language Server from Brackets side
  • Support for all communication types: IPC, Pipe, Socket and Standard I/O

TODO:

  • Move vscode-languageserver-protocol to Thirdparty
  • Tooling Manager
    • CodeHints
    • ParameterHints
    • Diagnostics
    • Jump to Def/Decl/Impl
    • Priority
    • Translate brackets events to LSP events
    • Default handlers for all the above Tooling Interfaces
  • Project level event handling
    • Project Switch
    • Reload with Extensions
  • Grunt modifications for build generation
  • UI
  • Tests

This feature can be experienced with the reference Language Client implementation for PHP here : #14671

Copy link
Contributor

@ingorichter ingorichter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can’t test it myself right now, but I wanted to leave a couple of comments before I’ll look into the functional details. Besides the feature implementation I recommend to run the linter and ensure that the formatting is consistent with all the remaining brackets sources (there might be inconsistencies too). Since this is a lot of new code we should ensure that it’s properly formatted and documented. Adding test cases is crucial for this sort of functionality. Adding a sample LSP client would help to demonstrate the use of the API and helps with the testing of this great new feature.

define(function (require, exports, module) {
"use strict";

class Client{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
class Client{
class Client {

Please ensure that the formatting is consistent across the files, e.g. white space between text and { as an example.

@@ -0,0 +1,150 @@

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: obsolete empty line

*/
function receiveMessageFromServer(event, msgObj) {

if(msgObj.param.method && _callbackList[msgObj.serverName+msgObj.param.method]){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would assert that msgObj is defined and param exists before checkin for method. Same applies for accessing _callbackList. There is a some potential to create a variable and assign the constructed key msgObj.serverName+msgObj.param.

*
*/

define(function (require, exports, module) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to write unit tests for all this new functionality to ensure that edge cases and error conditions are properly excercises

* otherwise.
*/
function isHintDisplayed() {
return hintState.visible === true;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return hintState.visible === true;
return hintState.visible;

should be enough ;-)

*
*/
function dismissHint() {
if (hintState.visible) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you could call isHintDisplayed instead

@swmitra swmitra requested a review from petetnt March 29, 2019 16:36
Copy link
Collaborator

@petetnt petetnt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some comments :) haven't worked with Brackets codebase in a while so there are couple of questions, couple of smaller nits and maybe one or two issues. Generally looks good to me otherwise

functionInfo = functionInfo || this.session.getFunctionInfo();
if (!functionInfo.inFunctionCall) {
this.cleanHintState();
result.reject(null);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: Should/can this return early?

Suggested change
result.reject(null);
return result.reject(null);

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks for the catch. It can return early. Basically, since we were returning a promise which could be resolved only once, it was still functioning correctly.

* language IDs for languages to remove the provider for. Defaults
* to all languages.
*/
RegistrationHandler.prototype.removeProvider = function (provider, targetLanguageId) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are private methods still underscored by practice? If they are this should probably be _removeProvider

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, the function isn't meant to be private. Fixed the documentation.

src/languageTools/DefaultEventHandlers.js Outdated Show resolved Hide resolved
src/languageTools/DefaultProviders.js Outdated Show resolved Hide resolved
src/languageTools/LanguageClient/package.json Outdated Show resolved Hide resolved
src/languageTools/LanguageTools.js Outdated Show resolved Hide resolved
@@ -0,0 +1,82 @@
/*
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is the same as LanguageClient/Utils.js, should they just use same file?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LanguageClient here would work in the Node Context while Utils works in the CEF/Brackets context. The function APIs and logic are the same but there are subtle differences internally wherein the former one we use node.js built-ins and browser ones in the later.

text-overflow: ellipsis;
line-height: 1em;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deprecated property?

Copy link
Collaborator

@shubhsnov shubhsnov Apr 1, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually currently we're running on slightly older versions of CEF 2623 in Win, 2704 on Mac and 2785 in Linux, where the property works fine. We're using this property elsewhere in brackets core as well, so I think we should do the cleanup collectively together as an issue when we upgrade CEF.

}

.highlight .hint-doc {
display: -webkit-box;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this and -webkit-box-orient just be display: flex and flex-direction: column?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my comment above.

@shubhsnov
Copy link
Collaborator

@petetnt Thanks for the review. I've addressed the comments.

Copy link
Collaborator

@swmitra swmitra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

src/brackets.js Outdated
require("languageTools/DefaultProviders");
require("languageTools/DefaultEventHandlers");

//load language features
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: fix indentation.

@swmitra swmitra merged commit df7aea4 into adobe:master Apr 2, 2019
shubhsnov added a commit that referenced this pull request Apr 2, 2019
* LSP Initial set of changes

* Adding comments and a bit of cleanup

* Adding php client for lsp

* further cleanup

* removing dependency on HintUtils

* removing phpClient extension from this branch

* Cleanup

* fixing eslint errors

* Refactoring code- Removing dependency on JSUtils ANd adding basic structure for client capabilities

* Bug Fix: too many listeners were getting attached to node process + code cleanup

* putting null check and settign capabilities to default values

* reinitializing server on workspace change and moving out capabilities from client code

* cleanup

* First cut for LSP support in Brackets

* First cut for LSP support in Brackets

* Adding client infrastructure

* Adding client infrastructure

* Adding handlers on Language Client Proxy, fixing eslint errors

* Adding handlers on Language Client Proxy, fixing eslint errors

* Fixing protocol adapter

* Fixing protocol adapter

* Fix typo

* Fix typo

* Removing older implementation

* Removing older implementation

* Added error checks to the auto update mechanism. So in case the auto update mechansim fails, we will now give chance to the default update process Handler to handle the update mechanism (Which is essentially taking the user to brackets.io). (#14605)

* First cut for LSP support in Brackets

* First cut for LSP support in Brackets

* Adding client infrastructure

* Adding client infrastructure

* Adding handlers on Language Client Proxy, fixing eslint errors

* Adding handlers on Language Client Proxy, fixing eslint errors

* Fixing protocol adapter

* Fixing protocol adapter

* Fix typo

* Fix typo

* Removing older implementation

* Removing older implementation

* Removing custom comments

* Removing custom comments

* Fixing Typo

* Fixing Typo

* Add missing Params in function call

* Add missing Params in function call

* Correcting message type, handlers

* Correcting message type, handlers

* Minor correction on active project change

* Minor correction on active project change

* Correcting the message format for didChange

* Correcting the message format for didChange

* Changing custom notification and request handlers, correcting typo, adding catch block for Connection

* Changing custom notification and request handlers, correcting typo, adding catch block for Connection

* Stop Creation of Multiple Language Servers

* Stop Creation of Multiple Language Servers

* Make Language Client Generic, address review comments

* Make Language Client Generic, address review comments

* Correcting param descriptions

* Correcting param descriptions

* Modifying events handling logic for Language Client, add formatting option for communication params

* Modifying events handling logic for Language Client, add formatting option for communication params

* Add handlers for node side

* Add handlers for node side

* Removing explicit param creation, substituting with appropriate checks

* Removing explicit param creation, substituting with appropriate checks

* Fixing lint errors in MessageHandler.js

* Fixing lint errors in MessageHandler.js

* Messaging related cleanup

* Messaging related cleanup

* Adding default providers and feature managers

* Adding default providers and feature managers

* Adding banner and fixing lint error

* Adding banner and fixing lint error

* fix spacing issue

* fix spacing issue

* Fix spacing issues

* Fix spacing issues

* Add filetype checks for all events, minor server info corrections

* Add filetype checks for all events, minor server info corrections

* Handling Reload with Extension Scenario, minor JumpToDef provider fix

* Handling Reload with Extension Scenario, minor JumpToDef provider fix

* Correcting Typo

* Correcting Typo

* Adding bug fixes

* Adding bug fixes

* Adding bug fixes 2

* Adding bug fixes 2

* Addressing Review: Fixing minor typo

* Addressing Review: Fixing minor typo

* Minor bug fixes, functionality enhancements

* Minor bug fixes, functionality enhancements

* Adding tests for Language Server Support: first cut

* Adding tests for Language Server Support: first cut

* Adding banner, fixing lint errors

* Adding banner, fixing lint errors

* Adding dependency related tasks

* Adding dependency related tasks

* Fixing npm environment string

* Fixing npm environment string

* Changing handler name

* Changing handler name

* Changing file name to ClientLoader

* Changing file name to ClientLoader

* Changing variable name appropriately

* Changing variable name appropriately

* Grunt related changes for build

* Grunt related changes for build

* Adding additional requests and notifications for handling various scenarios

* Adding additional requests and notifications for handling various scenarios

* Adding Path Converter Utilities

* Adding Path Converter Utilities

* Changing Ternary operator to OR operater

* Changing Ternary operator to OR operater

* Addressing review comments

* Addressing review comments

* Removing the handler for editor change, will be handled explicitely

* Removing the handler for editor change, will be handled explicitely

* Patching JavaScriptCodeHints

* Patching JavaScriptCodeHints

* Preferences infra for LanguageTools

* Preferences infra for LanguageTools

* Fixing JS ParameterHints

* Fixing JS ParameterHints

* Fixing Default Parameter Hints Provider

* Fixing Default Parameter Hints Provider

* Fixing Path Converters

* Fixing Path Converters

* Fixing Lint in PathConverters

* Fixing Lint in PathConverters

* Retaining Posix Path on Win

* Retaining Posix Path on Win

* Fixing lint errors

* Fixing lint errors

* Fixing Node side Utils

* Fixing Node side Utils

* Fixing Promise related Issues

* Fixing Promise related Issues

* Set Server Capability in Start call

* Set Server Capability in Start call

* Review Comments & Bug Fixes

* Review Comments & Bug Fixes

* Addressing Review Comments

* Addressing Review Comments

* Fixing Lint

* Fixing Lint

Co-authored-by: Shubham Yadav <shubyada@adobe.com>
shubhsnov added a commit that referenced this pull request Apr 2, 2019
* LSP Initial set of changes

* Adding comments and a bit of cleanup

* Adding php client for lsp

* further cleanup

* removing dependency on HintUtils

* removing phpClient extension from this branch

* Cleanup

* fixing eslint errors

* Refactoring code- Removing dependency on JSUtils ANd adding basic structure for client capabilities

* Bug Fix: too many listeners were getting attached to node process + code cleanup

* putting null check and settign capabilities to default values

* reinitializing server on workspace change and moving out capabilities from client code

* cleanup

* First cut for LSP support in Brackets

* First cut for LSP support in Brackets

* Adding client infrastructure

* Adding client infrastructure

* Adding handlers on Language Client Proxy, fixing eslint errors

* Adding handlers on Language Client Proxy, fixing eslint errors

* Fixing protocol adapter

* Fixing protocol adapter

* Fix typo

* Fix typo

* Removing older implementation

* Removing older implementation

* Added error checks to the auto update mechanism. So in case the auto update mechansim fails, we will now give chance to the default update process Handler to handle the update mechanism (Which is essentially taking the user to brackets.io). (#14605)

* First cut for LSP support in Brackets

* First cut for LSP support in Brackets

* Adding client infrastructure

* Adding client infrastructure

* Adding handlers on Language Client Proxy, fixing eslint errors

* Adding handlers on Language Client Proxy, fixing eslint errors

* Fixing protocol adapter

* Fixing protocol adapter

* Fix typo

* Fix typo

* Removing older implementation

* Removing older implementation

* Removing custom comments

* Removing custom comments

* Fixing Typo

* Fixing Typo

* Add missing Params in function call

* Add missing Params in function call

* Correcting message type, handlers

* Correcting message type, handlers

* Minor correction on active project change

* Minor correction on active project change

* Correcting the message format for didChange

* Correcting the message format for didChange

* Changing custom notification and request handlers, correcting typo, adding catch block for Connection

* Changing custom notification and request handlers, correcting typo, adding catch block for Connection

* Stop Creation of Multiple Language Servers

* Stop Creation of Multiple Language Servers

* Make Language Client Generic, address review comments

* Make Language Client Generic, address review comments

* Correcting param descriptions

* Correcting param descriptions

* Modifying events handling logic for Language Client, add formatting option for communication params

* Modifying events handling logic for Language Client, add formatting option for communication params

* Add handlers for node side

* Add handlers for node side

* Removing explicit param creation, substituting with appropriate checks

* Removing explicit param creation, substituting with appropriate checks

* Fixing lint errors in MessageHandler.js

* Fixing lint errors in MessageHandler.js

* Messaging related cleanup

* Messaging related cleanup

* Adding default providers and feature managers

* Adding default providers and feature managers

* Adding banner and fixing lint error

* Adding banner and fixing lint error

* fix spacing issue

* fix spacing issue

* Fix spacing issues

* Fix spacing issues

* Add filetype checks for all events, minor server info corrections

* Add filetype checks for all events, minor server info corrections

* Handling Reload with Extension Scenario, minor JumpToDef provider fix

* Handling Reload with Extension Scenario, minor JumpToDef provider fix

* Correcting Typo

* Correcting Typo

* Adding bug fixes

* Adding bug fixes

* Adding bug fixes 2

* Adding bug fixes 2

* Addressing Review: Fixing minor typo

* Addressing Review: Fixing minor typo

* Minor bug fixes, functionality enhancements

* Minor bug fixes, functionality enhancements

* Adding tests for Language Server Support: first cut

* Adding tests for Language Server Support: first cut

* Adding banner, fixing lint errors

* Adding banner, fixing lint errors

* Adding dependency related tasks

* Adding dependency related tasks

* Fixing npm environment string

* Fixing npm environment string

* Changing handler name

* Changing handler name

* Changing file name to ClientLoader

* Changing file name to ClientLoader

* Changing variable name appropriately

* Changing variable name appropriately

* Grunt related changes for build

* Grunt related changes for build

* Adding additional requests and notifications for handling various scenarios

* Adding additional requests and notifications for handling various scenarios

* Adding Path Converter Utilities

* Adding Path Converter Utilities

* Changing Ternary operator to OR operater

* Changing Ternary operator to OR operater

* Addressing review comments

* Addressing review comments

* Removing the handler for editor change, will be handled explicitely

* Removing the handler for editor change, will be handled explicitely

* Patching JavaScriptCodeHints

* Patching JavaScriptCodeHints

* Preferences infra for LanguageTools

* Preferences infra for LanguageTools

* Fixing JS ParameterHints

* Fixing JS ParameterHints

* Fixing Default Parameter Hints Provider

* Fixing Default Parameter Hints Provider

* Fixing Path Converters

* Fixing Path Converters

* Fixing Lint in PathConverters

* Fixing Lint in PathConverters

* Retaining Posix Path on Win

* Retaining Posix Path on Win

* Fixing lint errors

* Fixing lint errors

* Fixing Node side Utils

* Fixing Node side Utils

* Fixing Promise related Issues

* Fixing Promise related Issues

* Set Server Capability in Start call

* Set Server Capability in Start call

* Review Comments & Bug Fixes

* Review Comments & Bug Fixes

* Addressing Review Comments

* Addressing Review Comments

* Fixing Lint

* Fixing Lint

Co-authored-by: Shubham Yadav <shubyada@adobe.com>
@grire974
Copy link

grire974 commented May 2, 2019

Wrong place for this comment I'm sure - but I just saw this feature (looks awesome thanks!) can't find documentation anywhere on how to implement it; for example can I install any of these LSP's?
https://langserver.org/

Some of the LSP's in this list (e.g. I'm interested in Java at the moment) have examples on how to install them on VSCode for example; I looked on the brackets wiki & don't see anything there either under Extensions->Languages that makes any mention of this new functionality.

@shubhsnov
Copy link
Collaborator

@grire974 This is a new feature and we're actively working on making the documentation better and more accessible for the developers. You can look at this page to get started.

We've tried to make sure that the Server integration part isn't too far off from how it works in VSCode, so basically, any extension which works for VSCode will work for us and often in the same way in terms of code pertaining to spawning a language server or interacting with it.

Please reach out to us in case you have any queries in the form of issues. Thanks for your interest.

@grire974
Copy link

grire974 commented May 3, 2019

Ah ok - that's pretty informative thanks. Sounds like then to answer my own question that the LSP's I linked to at langserver.org above might not work out of the box but could possibly be a starting point to modify into the brackets format (e.g. main.js etc...)? I've written a couple of basic brackets extensions before, so this could be a good next project for me!

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.

10 participants