-
Notifications
You must be signed in to change notification settings - Fork 7.6k
Language Server Protocol Support for Brackets #14606
Conversation
…ucture for client capabilities
… from client code
There was a problem hiding this 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.
src/lsp/ClientTemplate.js
Outdated
define(function (require, exports, module) { | ||
"use strict"; | ||
|
||
class Client{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
class Client{ | |
class Client { |
Please ensure that the formatting is consistent across the files, e.g. white space between text and {
as an example.
src/lsp/LSPInterface.js
Outdated
@@ -0,0 +1,150 @@ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: obsolete empty line
src/lsp/LSPInterface.js
Outdated
*/ | ||
function receiveMessageFromServer(event, msgObj) { | ||
|
||
if(msgObj.param.method && _callbackList[msgObj.serverName+msgObj.param.method]){ |
There was a problem hiding this comment.
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
.
src/lsp/LSPInterface.js
Outdated
* | ||
*/ | ||
|
||
define(function (require, exports, module) { |
There was a problem hiding this comment.
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
src/lsp/ParameterHintManager.js
Outdated
* otherwise. | ||
*/ | ||
function isHintDisplayed() { | ||
return hintState.visible === true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return hintState.visible === true; | |
return hintState.visible; |
should be enough ;-)
src/lsp/ParameterHintManager.js
Outdated
* | ||
*/ | ||
function dismissHint() { | ||
if (hintState.visible) { |
There was a problem hiding this comment.
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
Fixing Promise related Issues
Set Server Capability in Start call
Review Comments & Bug Fixes
There was a problem hiding this 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); |
There was a problem hiding this comment.
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?
result.reject(null); | |
return result.reject(null); |
There was a problem hiding this comment.
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.
src/extensions/default/JavaScriptCodeHints/ParameterHintsProvider.js
Outdated
Show resolved
Hide resolved
* language IDs for languages to remove the provider for. Defaults | ||
* to all languages. | ||
*/ | ||
RegistrationHandler.prototype.removeProvider = function (provider, targetLanguageId) { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
@@ -0,0 +1,82 @@ | |||
/* |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deprecated property?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See my comment above.
@petetnt Thanks for the review. I've addressed the comments. |
Fix author
Fixing Author Information
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: fix indentation.
* 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 <[email protected]>
* 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 <[email protected]>
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? 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. |
@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. |
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! |
This covers the first cut of Language Server Protocol Support for Brackets.
Basic core implementation to:
TODO:
This feature can be experienced with the reference Language Client implementation for PHP here : #14671