- Generic programming languages are often complex and have many features, which makes it challenging to learn the skills for developing the Visual Studio Code extension using LSP (Language Server Protocol). To simplify this, the code defines a toy language called Power Fx Alpha, which is based on Power Fx syntax.
- PowerFxAlpha simplifies complex types and adds syntax for
imports
andcustom-defined functions
. PowerFxAlpha supports only parser.- The samples are in the
syntaxes/powerfx-script-sample
directory. - Power Fx is a low-code language used in the Microsoft Power Platform, mainly in Power Apps, which is a low-code application development tool.
- The PowerFxAlpha lexer, parser, and TextMate grammar were generated using GPT. The grammar files are based on Power Fx expression-grammar.grammar from the official Power Fx documentation.
- The samples are in the
Important: The code in this repository is intended for proof-of-concept purposes only.
- VS Code <-> Type script: Extension & LSP Client (nodejs) <-- LSP -- > Python: LSP Server (pygls) <-> Parser
sequenceDiagram
participant VSCode as VS Code
participant TS as TypeScript: <br/> Extension & LSP Client (nodejs)
participant Python as Python: <br/> LSP Server <br/> (pygls)
participant Parser as Parser
autonumber
VSCode->>TS: Request
TS->>Python: Forward Request
Python->>Parser: Parse or Process
Parser-->>Python: Return Results
Python-->>TS: Send Response
TS-->>VSCode: Deliver Results
- Extension & LSP Client - ANSI C Example: The
src\languageServer
directory in the repository is actually an LSP client. - Language Server (LSP Backend & Parser) - ANSI C Example: The VS Code extension officially supports the Node SDK for the LSP server. However, the repository implements the LSP server using C#. The official documentation for the VS Code extension states that
The language server can be implemented in any language, as long as it can communicate with the language client using the Language Server Protocol.
- Video Overview on YouTube
package.json
: add your new language support configuration in the "contributes" section.- Language Configuration (Optional): If you want to add additional features like comment toggling, create a
language-configuration.json
file. PowerFxAlphaLexer.g4
: PowerFxAlpha lexerPowerFxAlphaParser.g4
: PowerFxAlpha parserPowerFxAlpha.tmLanguage.json
: TextMate grammarexpression-grammar.grammar
: official Power Fx expression grammar
Rename
vscode-client/src/config.template.json
tovscode-client/src/config.json
and fill out the values in the config.
To start the server, run the following command in your terminal:
python server/lsp_server.py
To run the client, follow these steps:
- Open the project in Visual Studio Code.
- Navigate to
vscode-client/src/extension.ts
. - Click on the
Run
menu in Visual Studio Code. - Select
Start Debugging (F5)
.
- If you set
debugMode
totrue
invscode-client/src/config.json
, the server and client will connect via TCP at127.0.0.1
on port8080
. otherwise, the client will automatically launch the server as a child process using the defined Python path invscode-client/src/config.json
.
vscode-pfx.mp4
- Hover (Echo): Show info when hovering over code elements.
- Rename Function: Rename function's name in the code context.
- Custom Notification: Create a command for notifications through user input from client-server communication.
- Client Notification: Enable the client to pop up a hello-world notification by command.
- Syntax Highlighting: Implement syntax highlighting.
- Chat: A chat UI implementation that displays responses from the server.
- Create Your First Extension
- VS Code Extension API > VS Code Extension Samples & Example language server
- Language Server Protocol Samples
- Language Server Protocol Documentation > Template for VS Code Python Tools Extensions
- Integrate Language-Server with VS-Code extension
- Python extension for Visual Studio Code
- Readthedocs.io
- Power Fx kernel for .NET Interactive
- pygls: A Pythonic generic implementation of the Language Server Protocol. The SDK is designed for a JSON-RPC interface and is not specific to the Python programming language. (pygls v2.0) git