-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
new module for lsp related stuff. test fixes.
eventually more of the lsp-model include functions have to be moved to lsp-util.
- Loading branch information
1 parent
3e391ad
commit aa9e7ec
Showing
7 changed files
with
103 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
(defmodule code-util-tests | ||
(defmodule code-util | ||
(export | ||
(add-code-paths 1))) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
(defmodule lsp-util | ||
(export (completion-item-to-json 1))) | ||
|
||
(include-lib "apps/lfe-ls/include/lsp-model.lfe") | ||
|
||
(defun completion-item-to-json (citem) | ||
"Converts `completion-item` to LSP json representation." | ||
(let ((module (completion-item-module citem)) | ||
(func (completion-item-func citem)) | ||
(arity (completion-item-arity citem)) | ||
(detail (completion-item-detail citem)) | ||
(kind (completion-item-kind citem))) | ||
(let* ((base-label (case func | ||
('null (lfe_io:format1 "~s" `(,module))) | ||
(#"" (lfe_io:format1 "~s" `(,module))) | ||
(fn (lfe_io:format1 "~s:~s" `(,module ,fn))))) | ||
(label (list_to_binary | ||
(case arity | ||
('null base-label) | ||
(ar (lfe_io:format1 "~s~s" | ||
`(,base-label | ||
,(lfe_io:format1 "/~p" `(,ar)))))))) | ||
(insertText (case func | ||
('null module) | ||
(#"" module) | ||
(fn (case arity | ||
('null fn) | ||
(0 fn) | ||
(n (list_to_binary | ||
(lists:foldl (lambda (i acc) | ||
(lfe_io:format1 "~s ${~p:arg~p}" `(,acc ,i ,i))) | ||
fn | ||
(lists:seq 1 n)))))))) | ||
(result `(#(#"label" ,label) | ||
#(#"kind" ,kind) | ||
#(#"detail" ,detail) | ||
#(#"insertTextFormat" 2) | ||
#(#"insertText" ,insertText)))) | ||
;;(logger:notice "result: ~p" `(,result)) | ||
result))) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
(defmodule lsp-util-tests | ||
(behaviour ltest-unit)) | ||
|
||
(include-lib "ltest/include/ltest-macros.lfe") | ||
(include-lib "apps/lfe-ls/include/lsp-model.lfe") | ||
|
||
(deftest generate-json--arity-null | ||
(is-equal '(#(#"label" #"foo:bar") | ||
#(#"kind" 3) | ||
#(#"detail" #"") | ||
#(#"insertTextFormat" 2) | ||
#(#"insertText" #"bar")) | ||
(lsp-util:completion-item-to-json | ||
(make-completion-item | ||
module #"foo" | ||
func #"bar" | ||
arity 'null | ||
kind (completion-item-kind-function))))) | ||
|
||
(defmacro make-citem (arity) | ||
`(lsp-util:completion-item-to-json | ||
(make-completion-item | ||
module #"foo" | ||
func #"bar" | ||
arity ,arity | ||
kind (completion-item-kind-function)))) | ||
|
||
(deftest generate-json--arity-0 | ||
(is-equal '(#(#"label" #"foo:bar/0") | ||
#(#"kind" 3) | ||
#(#"detail" #"") | ||
#(#"insertTextFormat" 2) | ||
#(#"insertText" #"bar")) | ||
(make-citem 0))) | ||
|
||
(deftest generate-json--arity-1 | ||
(is-equal '(#(#"label" #"foo:bar/1") | ||
#(#"kind" 3) | ||
#(#"detail" #"") | ||
#(#"insertTextFormat" 2) | ||
#(#"insertText" #"bar ${1:arg1}")) | ||
(make-citem 1))) | ||
(deftest generate-json--arity-2 | ||
(is-equal '(#(#"label" #"foo:bar/2") | ||
#(#"kind" 3) | ||
#(#"detail" #"") | ||
#(#"insertTextFormat" 2) | ||
#(#"insertText" #"bar ${1:arg1} ${2:arg2}")) | ||
(make-citem 2))) | ||
(deftest generate-json--arity-3 | ||
(is-equal '(#(#"label" #"foo:bar/3") | ||
#(#"kind" 3) | ||
#(#"detail" #"") | ||
#(#"insertTextFormat" 2) | ||
#(#"insertText" #"bar ${1:arg1} ${2:arg2} ${3:arg3}")) | ||
(make-citem 3))) |