Git Product home page Git Product logo

language-server's Introduction

Language Server and Implementation

This repository contains the source code for the example implementation of a language server referenced in the book \title of the book. This language server implementation is associated with an example client implementation as well. The referenced client implementation is done for the VS Code client.

About the Book

Authors

Introduction

The Language Server Protocol (LSP) has been one of the most talked about topics during the past few years when it comes to the tooling for programming languages. With the advancement of the developer tools and the programming languages, developers started to rely more and more on advanced tools and enhanced language services. When we consider one of the most focused branches of developer tools which is IDEs and text editors, there are many vendors who have released various editing tools in the past couple of decades. When we consider the number of programming languages along with the number of smart editors nowadays, in order to support language intelligence among the editors, these vendors have to repeat the same thing. The Language Server Protocol was introduced to solve this particular problem, and today it has become the norm of the development tools’ language intelligence provider. By adopting the LSP, tools such as text editors and integrated development environments (IDEs) could expand the capabilities and avoid the users’ burden of switching between the development tools for trying new programming languages and frameworks. This book is for the developers who are passionate about developing programming language tools. In this book, we provide the readers a comprehensive understanding about the Language Server Protocol and how to develop a Language Server from scratch. The readers will be guided with code samples to provide a better understanding about the server implementation by adhering to the user experience best practices as well as the LSP best practices. The readers are expected to use the book along with the example implementation, in order to get a better understanding about the concepts described in the book. In the example implementation, the book refers to VS Code as the client; however, the readers can use any other client and integrate the server implementation as desired.

Technologies

  • The client implementation is done with TypeScript.
  • Language Server implementation is done with Java and Java-11 would be preffered
  • Language Server implementation is done for the Ballerina programming language. The default implementation is done for Ballerina Swan Lake Beta 3. You can read more and learn about Ballerina programming language in the official doccumentation
  • Gradle is used as the build tool for the server component
  • Node JS [v12.20.0 at least] and NPM [6.14.x at least] is used as for the client component

How to build

This repository contains two components as the client and the server implementation. You have to build these components individually.

Step 1

Clone the repo

Step 2

Set the github access token In order to build the repo, you have the set the github access token in the first place. In order to do so, execute the following command

In Unix

export packageUser='your_github_user_name'
export packagePAT='your_github_personal_access_token'

In Windows

set packageUser='your_github_user_name'
set packagePAT='your_github_personal_access_token'

Build the Server Implementation Go to the repo root and execute the following command to build the server implementation. ./gradlew clean build The server implementation will copy the particular uber-jar artifact to REPO_ROOT/client directory.

Build the Client Implementation Go to the REPO_ROOT/client/ls-client directory and execute the following command to install the Dependencies npm install Now execute the following command to build the client and generate the .vsix VS Code plugin artifact npm run build

Using the Extension and the Language Server

Prerequisites

Usage

  • Install the built .vsix extension artifact. The plugin itself will start the language server once a .bal file is opened
  • Open a Ballerina source file from the VSCode editor.
  • Explore the language features such as auto-completions, find references, and etc

Debugging the Implementation

Enable trace logs for the server implementation

  • You can explore the trace logs for the messages passed between the language server and the client by adding the following configuration option in the user settings. "ballerina-lang-client.trace.server": "verbose"

Debugging the Language Server

Step 1

Open the REPO_ROOT/client/ls-client/ directory in VS Code.

Step 2

Go to REPO_ROOT/client/ls-client/.vscode/launch.json file and set the LSDEBUG config value to true

Step 3

Run the extension from VSCode

Known Issues

language-server's People

Contributors

nadeeshaan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

language-server's Issues

gradle clean build

Hello,

after doing ./gradlew clean build I get the following error:

* Where:
Build file '/Users/yoobi/Documents/Gitlab/Examples/language-server/launchers/build.gradle' line: 50

* What went wrong:
Could not determine the dependencies of task ':launchers:uberJar'.
> Could not resolve all files for configuration ':launchers:runtimeClasspath'.
   > Could not resolve org.ballerinalang:ballerina-lang:2.0.0-beta.3.
     Required by:
         project :launchers > project :server:server-core
         project :launchers > project :server:server-core > project :server:server-api
      > Could not resolve org.ballerinalang:ballerina-lang:2.0.0-beta.3.
         > Could not get resource 'https://maven.pkg.github.com/ballerina-platform/*/org/ballerinalang/ballerina-lang/2.0.0-beta.3/ballerina-lang-2.0.0-beta.3.pom'.
            > Username must not be null!
   > Could not resolve org.ballerinalang:ballerina-parser:2.0.0-beta.3.
     Required by:
         project :launchers > project :server:server-core
         project :launchers > project :server:server-core > project :server:server-api
      > Could not resolve org.ballerinalang:ballerina-parser:2.0.0-beta.3.
         > Could not get resource 'https://maven.pkg.github.com/ballerina-platform/*/org/ballerinalang/ballerina-parser/2.0.0-beta.3/ballerina-parser-2.0.0-beta.3.pom'.
            > Username must not be null!
   > Could not resolve org.ballerinalang:ballerina-tools-api:2.0.0-beta.3.
     Required by:
         project :launchers > project :server:server-core
         project :launchers > project :server:server-core > project :server:server-api
      > Could not resolve org.ballerinalang:ballerina-tools-api:2.0.0-beta.3.
         > Could not get resource 'https://maven.pkg.github.com/ballerina-platform/*/org/ballerinalang/ballerina-tools-api/2.0.0-beta.3/ballerina-tools-api-2.0.0-beta.3.pom'.
            > Username must not be null!
   > Could not resolve org.ballerinalang:formatter:2.0.0-beta.3.
     Required by:
         project :launchers > project :server:server-core
         project :launchers > project :server:server-core > project :server:server-api
      > Could not resolve org.ballerinalang:formatter:2.0.0-beta.3.
         > Could not get resource 'https://maven.pkg.github.com/ballerina-platform/*/org/ballerinalang/formatter/2.0.0-beta.3/formatter-2.0.0-beta.3.pom'.
            > Username must not be null!
   > Could not resolve org.ballerinalang:formatter-core:2.0.0-beta.3.
     Required by:
         project :launchers > project :server:server-core
         project :launchers > project :server:server-core > project :server:server-api
      > Could not resolve org.ballerinalang:formatter-core:2.0.0-beta.3.
         > Could not get resource 'https://maven.pkg.github.com/ballerina-platform/*/org/ballerinalang/formatter-core/2.0.0-beta.3/formatter-core-2.0.0-beta.3.pom'.
            > Username must not be null!
   > Could not resolve org.ballerinalang:toml-parser:2.0.0-beta.3.
     Required by:
         project :launchers > project :server:server-core
         project :launchers > project :server:server-core > project :server:server-api
      > Could not resolve org.ballerinalang:toml-parser:2.0.0-beta.3.
         > Could not get resource 'https://maven.pkg.github.com/ballerina-platform/*/org/ballerinalang/toml-parser/2.0.0-beta.3/toml-parser-2.0.0-beta.3.pom'.
            > Username must not be null!

in the gradle I'm seeing

maven {
    url 'https://maven.pkg.github.com/ballerina-platform/*'
    credentials {
        username System.getenv('packageUser')
        password System.getenv('packagePAT')
    }
}

where can I get those login? Should I sign up somewhere ?

Failed to execute the command `bal home`

Hi,

the client extension typescript code to run command 'bal home' does not work on my windows machine.

extension.ts line 114:
let response = spawnSync('bal', ['home']);
returns error ENOENT, apparently because bal is not recognized as a cmd command (even though manual execution of bal inside a cmd does work correctly if Ballerina is installed).

to fix that I changed the code locally to
let response = spawnSync('cmd', ['/s', '/c', 'bal', 'home']);

After that I ran npm run build to generate a new .vsix client extension and reinstalled it in VS code. The language server and client worked fine after that.

This fix will only work on windows! To make it work globally an operating system check has to be implemented first which then calls spawnSync with the correct parameters.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.