Skip to content

playsrc/http-language-server

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 

HTTP Language Server

Python Typescript GitHub Sponsors

Warning This project is under development.

The HTTP Language Server is a LSP implementation for HTTP. It helps you to easily write your HTTP messages and requests by leveraging features like completion, hover documentation and diagnostics.

In the early stages, breaking changes can occur frequently, so it's important that if want to use this server, to use it with caution and please report any bugs that you might encounter.

Development

Contributions are welcome! Please create an Issue or Pull Request if you encounter any problems or have suggestions for improvement.

Project Setup

# Clone the repository
git clone https://github.com/mateusabelli/http-language-server.git

# Navigate to the project folder
cd http-language-server

Server Setup

# Navigate to the server folder
cd server/

# Create a new virtual environment
python -m venv venv

# Activate the environment
source venv/bin/activate

# Install the required dependencies
python -m pip install -r requirements.txt

Create .vscode/settings.json file and set python.interpreterPath to point to your python environment where pygls is installed.

{
    "python.defaultInterpreterPath": "${workspaceFolder}/server/venv/bin/python"
}
  • Switch to the Run and Debug View in the Sidebar (Ctrl+Shift+D).
  • Select Launch Server from the drop down.
  • Press to run the launch config (F5).

Client Setup

VSCode

# Navigate to the client folder
cd client/

# Install the required dependencies
npm install
  • Switch to the Run and Debug View in the Sidebar (Ctrl+Shift+D).
  • Select Launch Client from the drop down.
  • Press to run the launch config (F5).

Other Editors

Note Not tested, feedback is welcome!

These setup configurations won't work until a standalone executable is compiled from the server, but you can still use them if you know how to set it up to run from the server source code.

Neovim (without `lspconfig`)
vim.api.nvim_create_autocmd({ "BufEnter" }, {
  pattern = { ".http" },
  callback = function()
    vim.lsp.start({
      name = "http-language-server",
      cmd = { "http-language-server --stdio" },
      root_dir = vim.fs.dirname(vim.fs.find({ ".git" }, { upward = true })[1])
    })
  end,
})
Neovim (with `lspconfig`)

After having the dependencies installed you will need to have a working LSP setup in Neovim using lspconfig. Then you will need to follow lspconfig's Contributing guide to manually add this server configuration.

The config file: lua/lspconfig/server_configurations/http-language-server.lua

-- http-language-server.lua
local util = require 'lspconfig.util'

local bin_name = 'http-language-server'
local cmd = { bin_name, '--stdio' }

if vim.fn.has 'win32' == 1 then
  cmd = { 'cmd.exe', '/C', bin_name, '--stdio' }
end

return {
  default_config = {
    cmd = cmd,
    filetypes = { '.http' },
    root_dir = util.find_git_ancestor,
    single_file_support = true,
  },
}

Then you can activate this server in the lua file that you use to setup all the other servers.

require('lspconfig')['http_language_server'].setup({
  capabilities = capabilities,
  on_attach = on_attach
})
Vim (`vim-lsp`)
augroup HelloWorldPythonExample
au!
autocmd User lsp_setup call lsp#register_server({
    \ 'name': 'http-language-server',
    \ 'cmd': {server_info->['http-language-server', '--stdio']},
    \ 'allowlist': ['.http']
    \ })
augroup END
Emacs (`lsp-mode`)
(make-lsp-client :new-connection
(lsp-stdio-connection
  `(,(executable-find "http-language-server") "--stdio"))
  :activation-fn (lsp-activate-on ".http")
  :server-id 'http-language-server')
Sublime
{
    "clients": {
      "http-language-server": {
        "command": ["http-language-server", "--stdio"],
        "enabled": true,
        "selector": "source.http"
      }
    }
  }

Structure

.
├─ client // Language Client
  ├─ src
    └─ extension.ts // Language Client entry point
  └─ syntax // Syntax hightlighting settings

└─ server // Language Server
   ├─ __main__.py // Language Server entry point
   └─ server.py

References

Troubleshooting

If you encounter any issues while using the HTTP Language Server, please check the following:

  • Ensure that you have installed all of the required dependencies and have set up your environment correctly.
  • Check the documentation and issue tracker for common problems and their solutions.
  • If you are still having trouble, please create an issue with a detailed description of the problem and steps to reproduce it.

License

HTTP Language Server is licensed under the terms of the MIT license. See LICENSE.md