DEV Community

Shrijith Venkatramana
Shrijith Venkatramana

Posted on • Edited on

The Language Server Protocol - Building DBChat (Part 5)

Hello, I'm Shrijith. I'm building git-lrc, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. Star Us to help devs discover the project. Do give it a try and share your feedback for improving the product.

In this tutorial series, I am on a journey to build for myself DBChat - a simple tool for using AI chat to explore and evolve databases.

See previous posts to get more context:

  1. Building DBChat - Explore and Evolve Your DB with Simple Chat (Part 1)
  2. DBChat: Getting a Toy REPL Going in Golang (Part 2)
  3. DBChat Part 3 - Configure , Connect & Dump Databases
  4. Chat With Your DB via DBChat & Gemini (Part 4)

What is LSP and How Does It Relate to DBChat?

With DBChat, the idea is to explore and evolve databases with simple chat.

The most natural place for the above to happen is in the code editors we use day to day: VSCode, Cursor, Jetbrains, etc

The problem here is that - there are many editors/IDEs, which means we may need to build many extensions/plugins to get the desired level of developer coverage.

So - the "obvious" solution is to take out the core and implement it as a separate component, and then let the core power the various "UI" within extensions/plugins in different editors.

Essentially LSP is just that - it is the "backend server" for "extension frontends".

This is my understanding of LSP. The official definition of LSP is as follows from Microsoft:

Implementing support for features like autocomplete, goto definition, or documentation on hover for a programming language is a significant effort. Traditionally this work must be repeated for each development tool, as each provides different APIs for implementing the same features.

The idea behind a Language Server is to provide the language-specific smarts inside a server that can communicate with development tooling over a protocol that enables inter-process communication.

The idea behind the Language Server Protocol (LSP) is to standardize the protocol for how tools and servers communicate, so a single Language Server can be re-used in multiple development tools, and tools can support languages with minimal effort.

LSP is a win for both language providers and tooling vendors!

LSP Events (from the Editor Extension)

The first part of LSP is editor events. Here are things a user may do:

  1. Open document
  2. Edit text
  3. Execute "goto definition"
  4. Close document

As these events happen, some processes must be initiated to make them work.

Fulfillment of Events (from the server side)

For each of these events, the server is supposed to use its internal representation to provide appropriate responses.

For example on receiving "Open Document" event, the server may load the file contents into memory.

And on closing the file, the server may clear the memory for other programs to use.

LSP Event Samples - Goto Definition

The following is the Goto Definition request from any LSP enabled editor:

{
    "jsonrpc": "2.0",
    "id" : 1,
    "method": "textDocument/definition",
    "params": {
        "textDocument": {
            "uri": "file:///p%3A/mseng/VSCode/Playgrounds/cpp/use.cpp"
        },
        "position": {
            "line": 3,
            "character": 12
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Response from the LSP server:

{
    "jsonrpc": "2.0",
    "id": 1,
    "result": {
        "uri": "file:///p%3A/mseng/VSCode/Playgrounds/cpp/provide.cpp",
        "range": {
            "start": {
                "line": 0,
                "character": 4
            },
            "end": {
                "line": 0,
                "character": 11
            }
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

LSP Servers in The Wild

Python

Typescript

CSS

More example servers can be found at awesome-lsp-servers

The Specification

You can find the specification for the LSP in Microsoft's doc pages

Overall, we see a large number of messages/events defined by the protocol in the following areas:

  1. Lifecycle management: Initialize, Exit, et## Language Server Protocol (LSP)

The Language Server Protocol (LSP) is a powerful tool that enables seamless communication between editors or IDEs and language servers. This protocol defines a standard set of events and messages that allow for various functionalities like code completion, formatting, diagnostics, and more. Here's a breakdown of some key features:

  • Code Completion: Intelligent suggestions and auto-completion based on context.
  • Formatting: Automatically format your code to maintain consistency and readability.
  • Diagnostics: Get real-time feedback on potential errors or issues in your code.
  • Go To Definition/Implementation: Navigate effortlessly between definitions and implementations of functions, classes, and other code elements.

With such a comprehensive set of events/messages, LSP enables us to build multi tool, multi-platform plugins and extensions for various languages

Next Steps

Now that we have an overview of LSP, in the upcoming posts we will try to get an LSP going for DBChat. And once we have a basic LSP, we will attempt to build a nice and friendly UI for VSCode/Cursor first, and hopefully for other IDEs as well in the future.

git-lrc
*AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.*

Any feedback or contributors are welcome! It's online, source-available, and ready for anyone to use.

⭐ Star it on GitHub:

GitHub logo HexmosTech / git-lrc

Free, Unlimited AI Code Reviews That Run on Commit

git-lrc logo

git-lrc

Free, Unlimited AI Code Reviews That Run on Commit


git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.

See It In Action

See git-lrc catch serious security issues such as leaked credentials, expensive cloud operations, and sensitive material in log statements

git-lrc-intro-60s.mp4

Why

  • 🤖 AI agents silently break things. Code removed. Logic changed. Edge cases gone. You won't notice until production.
  • 🔍 Catch it before it ships. AI-powered inline comments show you exactly what changed and what looks wrong.
  • 🔁 Build a habit, ship better code. Regular review → fewer bugs → more robust code → better results in your team.
  • 🔗 Why git? Git is universal. Every editor, every IDE, every AI…




Top comments (0)