p4ls
p4ls copied to clipboard
LSP server for P4 language
P4LS
P4LS is an implementation of an LSP server for the P4 programming language.
Install
P4LSD Server
MacOS
Prebuilt binary packages for installing p4lsd server are available
for MacOS. To install the homebrew package use the following command
brew install dmakarov/homebrew-p4/p4ls
Linux
See Build section in this document for instructions on how to build from source.
Clients
Eclipse P4lang plugin
In addition to the P4 language server, the repository includes two LSP clients, one for Eclipse and another for Emacs. To build and install the Eclipse P4lang LSP client plugin follow these steps
cd clients/eclipse
mvn clean verify
If maven finished running without any error there should have been
created a subdirectory repository/target/repository in
clients/eclipse directory that contains the plugin jar file along
with the required dependencies. To install the plugin in Eclipse
- open the Eclipse menu Help >> Install New Software...
- Type or paste the absolute path to
repository/target/repositorydirectory, e.g./Users/dmakarov/work/try/p4ls/clients/eclipse/repository/target/repositoryin the Work with: text entry field and click Add... button. - Check Dependencies and P4lang: P4 editing in Eclipse IDE checkboxes and finish installing.
After restarting the Eclipse a new P4 perspective should be available
via Window >> Perspective >> Open Perspective >> Other...
menu. If p4lsd is in one of the known paths, p4lang plugin should
be able to find it, otherwise set the path to the p4lsd executable in
P4 Preferences.
P4lsd searches for compile_commands.json in subdirectory hierarchy
for each P4 source file it is processing. If you don't use cmake or
similar tool to build your P4 project, you can create
compile_commands.json file manually in an editor. For each file you
want p4lsd to analyze there should be an entry like the following
[
{
"directory": "/Users/dmakarov/work/try/p4ls/test",
"command": "/Users/dmakarov/work/try/opt/bin/p4c /Users/dmakarov/work/try/p4ls/test/main.p4",
"file": "/Users/dmakarov/work/try/p4ls/test/main.p4"
},
{
"directory": "/Users/dmakarov/work/try/p4ls/test",
"command": "/Users/dmakarov/work/try/opt/bin/p4c -I ../include /Users/dmakarov/work/try/p4ls/test/switch.p4",
"file": "/Users/dmakarov/work/try/p4ls/test/switch.p4"
}
]
There can be any number of {} blocks between the top-level brackets
[]. Usually the compile_commands.json is created by running
cmake with -DCMAKE_EXPORT_COMPILE_COMMANDS command line option, if
a project build is managed by cmake.
Emacs LSP mode client
Install melpa lsp-p4 package
Contribute
Build
brew install boost cmake ninja pkg-config rapidjson
git clone https://github.com/dmakarov/p4ls.git
cd p4ls
mkdir -p build/ninja/release
cd build/ninja/release
cmake -G Ninja -DCMAKE_BUILD_TYPE=Release -DHUNTER_ENABLED=OFF -DUNITTESTS_ENABLED=OFF <path to p4ls repository>
cmake --build . --target server/daemon/install