Pact is an open-source, Turing-incomplete smart contract language that has been purpose-built with blockchains first in mind. Pact focuses on facilitating transactional logic with the optimal mix of functionality in authorization, data management, and workflow.
The LSP server requires Pact 4.6
The Pact language server currently supports the following features:
-
Document diagnostics Every time a file is opened or saved, the file is analyzed using the pact executable and diagnostic information is supplied.
-
Completion of natives While typing, the LSP server provides completions for natives.
-
Documentation of natives Hovering over natives populates the documentation.
The LSP server needs to access the pact executable. Therefore, users can configure the path of the executable at server initialization by sending a configuration as follows:
{
"pact": {
"pactExe": "/path/to/pact"
}
}
The pact-lsp
executable accepts the --debug
flag to generate a log file which can be used to further
debug issues.
Using eglot:
(require 'pact-mode)
(require 'eglot)
(with-eval-after-load 'eglot
(add-to-list 'eglot-server-programs '(pact-mode . ("pact-lsp" ))))
(add-hook 'pact-mode-hook 'eglot-ensure)
Using lsp-mode
(require 'pact-mode)
(require 'lsp-mode)
(add-to-list 'lsp-language-id-configuration '(pact-mode . "pact"))
(lsp-register-client (make-lsp-client
:new-connection (lsp-stdio-connection "pact-lsp")
:activation-fn (lsp-activate-on "pact")
:server-id 'pact-lsp
:major-modes 'pact-mode)
)
(add-hook 'pact-mode-hook 'lsp-deferred)
)
or, in Doom Emacs
(after! (:all pact-mode lsp-mode)
(add-to-list 'lsp-language-id-configuration '(pact-mode . "pact"))
(lsp-register-client (make-lsp-client
:new-connection (lsp-stdio-connection "pact-lsp")
:activation-fn (lsp-activate-on "pact")
:server-id 'pact-lsp
:major-modes 'pact-mode)
)
)
(after! pact-mode
(add-hook 'pact-mode-hook (lambda () (lsp-deferred)))
)
Using vim-lsp:
if (executable('pact-lsp'))
au User lsp_setup call lsp#register_server({
\ 'name': 'pact-lsp',
\ 'cmd': {server_info->['pact-lsp']},
\ 'whitelist': ['pact'],
\ })
endif