Skip to content

stata language serve based on pygls, including auto completion, codestyle checking, etc.

License

Notifications You must be signed in to change notification settings

euglevi/stata-language-server

 
 

Repository files navigation

Stata-Language-Server

Write your Stata scripts more fluently!

This is a fork of the original VSCode LSP for Stata. I rigged it a little bit to adapt it to the new version of pygls, to neovim rather than VSCode and I added a formatter. I also changed the logic of some of the codestyle checking.

To install the LSP, just clone the repository and install it with pip or pipx (recommended):

git clone https://github.com/euglevi/stata-language-server
cd stata-language-server
pipx install .

To setup the LSP, you can use the instructions in the neovim manuals: https://neovim.io/doc/user/lsp.html.

I add here my personal config in ~/.config/nvim/lsp/stata-language-server.lua:

return {
	cmd = { "stata-language-server" }, -- Path to the server executable
	filetypes = { "stata" }, -- Filetypes to associate with the server
	root_markers = { ".git" },
	single_file_support = true,
	settings = {
		stata = {
			setMaxLineLength = 82, -- Example: Set max line length
			setIndentSpace = 4, -- Example: Set indentation spaces
			enableCompletion = true, -- Enable autocompletion
			enableDocstring = true, -- Enable hover documentation
			enableStyleChecking = true, -- Enable style checking
                        enableFormatting = true, -- Enable formatting
		},
	},
	capabilities = {
		workspace = {
			didChangeConfiguration = {
				dynamicRegistration = true,
			},
		},
	},
}

Description

An extension for Stata on Neovim. It provides codestyle checking, goto-definition, syntax tips, formatting and auto completion.

Developed based on language server, depending on Third-party Python library pygls.

Note: Another plugin is recommanded for syntax highlight since Stata Language Server doesn't provide this feature.

Supported Features

  • Codestyle Checking

    When editing a stata do-file, the extension will check documents and show bad codestyle using wavy underlines.

    diagnostic

  • Syntax tips while hovering

    When hovering on a complete command, a markdown formatted Syntax Description will appear.

    Note: Not available for 1.abbr. commands(eg: g, gen); 2.docstring included in another command's docstring(eg: replace belongs to generate)

    hover

    Note: Docstring files of this extension are only for academic purpose. The original work copyright belongs to StataCorp LLC. See ThirdPartyNotices.txt for details.

  • Goto Definition(generate varname =)

    Find and jump to the last generate place when right-click a variable name and click Go to Definition. Can match pattern like g(enerate).

    gotoDefinition

  • Syntax auto completion

    Auto-Completion for most stata commands. Only support complete syntax(eg: generate, not g(enerate)).

    completion

  • Formatting

    The LSP incorporates a script for formatting Stata do files based on the suggested codestyle. So far it has worked me well, but there could be bugs.

Requirements

  • Python >= 3.6

Settings

Setting Name Description Default Value
stataServer.setMaxLineLength Max line length for codestyle checking 120
stataServer.setIndentSpace Indent spaces for codetyle checking 4
stataServer.enableCompletion Turn on/off auto-completion true
stataServer.enableDocstring Turn on/off docstring tips true
stataServer.enableStyleChecking Turn on/off codestyle checking true
stataServer.enableFormatting Turn on/off formatting true

Release Notes

Refer to CHANGELOG.md

Issues

Submit issues if you find any bug or have any suggestion.

About

stata language serve based on pygls, including auto completion, codestyle checking, etc.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 99.8%
  • Stata 0.2%