From bad19ebc84047fdb9a5a17ee92443655ddf18333 Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 9 Jan 2022 22:31:43 +1100 Subject: [PATCH] lsp_signature setup was not documented in README. Add playground folder --- README.md | 9 +++ lua/navigator.lua | 2 +- playground/README.md | 31 ++++++++++ playground/go/fib.go | 8 +++ playground/go/fib_test.go | 17 ++++++ playground/go/func.go | 49 ++++++++++++++++ playground/go/func_test.go | 25 ++++++++ playground/go/funcc_test.go | 26 ++++++++ playground/go/interface.go | 67 +++++++++++++++++++++ playground/go/main.go | 31 ++++++++++ playground/go/struct.go | 39 ++++++++++++ playground/go/test/func.go | 26 ++++++++ playground/go/test/func.tst | 26 ++++++++ playground/go/test/func_test.go | 22 +++++++ playground/go/time.go | 70 ++++++++++++++++++++++ playground/init.lua | 101 ++++++++++++++++++++++++++++++++ playground/js/arrow.js | 7 +++ playground/js/closure.js | 12 ++++ playground/js/curry.js | 11 ++++ playground/js/date.js | 1 + playground/js/test.js | 3 + playground/js/tsconfig.json | 0 playground/py/hello.py | 79 +++++++++++++++++++++++++ playground/py/pd.py | 19 ++++++ playground/py/requirements.txt | 0 25 files changed, 680 insertions(+), 1 deletion(-) create mode 100644 playground/README.md create mode 100644 playground/go/fib.go create mode 100644 playground/go/fib_test.go create mode 100644 playground/go/func.go create mode 100644 playground/go/func_test.go create mode 100644 playground/go/funcc_test.go create mode 100644 playground/go/interface.go create mode 100644 playground/go/main.go create mode 100644 playground/go/struct.go create mode 100644 playground/go/test/func.go create mode 100644 playground/go/test/func.tst create mode 100644 playground/go/test/func_test.go create mode 100644 playground/go/time.go create mode 100644 playground/init.lua create mode 100644 playground/js/arrow.js create mode 100644 playground/js/closure.js create mode 100644 playground/js/curry.js create mode 100644 playground/js/date.js create mode 100644 playground/js/test.js create mode 100644 playground/js/tsconfig.json create mode 100644 playground/py/hello.py create mode 100644 playground/py/pd.py create mode 100644 playground/py/requirements.txt diff --git a/README.md b/README.md index 25b6367..bda3b8d 100644 --- a/README.md +++ b/README.md @@ -248,6 +248,10 @@ require'navigator'.setup({ -- please check mapping.lua for all keymaps treesitter_analysis = true, -- treesitter variable context transparency = 50, -- 0 ~ 100 blur the main window, 100: fully transparent, 0: opaque, set to nil or 100 to disable it + + lsp_signature_help = true, -- if you would like to hook ray-x/lsp_signature plugin in navigator + -- setup here. if it is nil, navigator will not init signature help + signature_help_cfg = nil, -- if you would like to init ray-x/lsp_signature plugin in navigator, and pass in your own config to signature help icons = { -- Code action code_action_icon = "🏏", @@ -376,6 +380,11 @@ require'navigator'.setup({ }) ``` +### Try it your self + +In `playground` folder, there is a `init.lua` and source code for you to play with. Check [playground/README.md](https://github.com/ray-x/navigator.lua/playground/README.md) for more +details + ### Default keymaps | mode | key | function | diff --git a/lua/navigator.lua b/lua/navigator.lua index ca41788..80bb325 100644 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -31,9 +31,9 @@ _NgConfigValues = { -- code_lens_action_prompt = {enable = true, sign = true, sign_priority = 40, virtual_text = true}, treesitter_analysis = true, -- treesitter variable context transparency = 50, -- 0 ~ 100 blur the main window, 100: fully transparent, 0: opaque, set to nil to disable it - signature_help_cfg = nil, -- if you would like to init ray-x/lsp_signature plugin in navigator, pass in signature help lsp_signature_help = true, -- if you would like to hook ray-x/lsp_signature plugin in navigator -- setup here. if it is nil, navigator will not init signature help + signature_help_cfg = nil, -- if you would like to init ray-x/lsp_signature plugin in navigator, pass in signature help lsp = { code_action = { enable = true, diff --git a/playground/README.md b/playground/README.md new file mode 100644 index 0000000..3cc7b5d --- /dev/null +++ b/playground/README.md @@ -0,0 +1,31 @@ +# Sandbox/Tutorial + +## introduction + +The folder contains `init.lua`, whitch is a minium vimrc to setup following plugins. Those plugin are some of the +most used plugins for programmer. + +- lspconfig +- treesitter +- navigator +- nvim-cmp +- luasnip +- aurora (colorscheme used in the screenshot) + +There also three folder `js`, `go`, `py`. Those folder have some basic source code you can play with. + +## run init.lua + +```bash +cd py +neovim -u init.lua +``` + +Move your cursor around and try to + +- Edit the code +- Check symbol reference with `gr` +- Check document symbol with `g0` +- treesitter symbole `gT` +- peek definition `gp` +- ... diff --git a/playground/go/fib.go b/playground/go/fib.go new file mode 100644 index 0000000..5f60a09 --- /dev/null +++ b/playground/go/fib.go @@ -0,0 +1,8 @@ +package main + +func Fib(n int) int { + if n < 2 { + return n + } + return Fib(n-1) + Fib(n-2) +} diff --git a/playground/go/fib_test.go b/playground/go/fib_test.go new file mode 100644 index 0000000..f024a29 --- /dev/null +++ b/playground/go/fib_test.go @@ -0,0 +1,17 @@ +package main + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestFib(t *testing.T) { + require.NoError(t, nil) + d := Fib(1) + fmt.Println(d) + if d != 1 { + t.Errorf("NewDog failled %v", d) + } +} diff --git a/playground/go/func.go b/playground/go/func.go new file mode 100644 index 0000000..9cfe523 --- /dev/null +++ b/playground/go/func.go @@ -0,0 +1,49 @@ +package main + +import ( + // "net/http" + "net/http/httptest" + "time" +) + +type Dog struct { + name string + age int + owner string +} + +func NewDog(name string, age int) *Dog { + return &Dog{name: name, age: age} +} + +// SetOwner +func (d *Dog) SetOwner(owner string) { + d.owner = owner +} + +// SetDogName +func (d *Dog) SetDogName(name string) { + if d == nil { + d = NewDog(name, 0) + d.name = name + } else { + d.name = name + } +} + +func (d *Dog) SetOwnerUtf8(name []byte) { +} + +func fun1() { +} + +func fun1_test() { + d := NewDog("", 1) + NewDog("abc", 12) + // fmt.Printf("abc", 1) + time.Date(12, 12, 12, 33, 12, 55, 22, nil) + + d.SetOwnerUtf8([]byte{1}) + w := httptest.NewRecorder() + w.Write([]byte{}) +} diff --git a/playground/go/func_test.go b/playground/go/func_test.go new file mode 100644 index 0000000..ffa356b --- /dev/null +++ b/playground/go/func_test.go @@ -0,0 +1,25 @@ +package main + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestDog(t *testing.T) { + require.NoError(t, nil) + d := NewDog("Fibi", 4) + fmt.Println(d.name) + if d.name != "Fibi" { + t.Errorf("NewDog failled %v", d) + } +} + +func TestCat(t *testing.T) { + d := NewDog("Fibi cat", 4) + fmt.Println(d.name) + if d.name != "Fibi cat" { + t.Errorf("NewDog failled %v", d) + } +} diff --git a/playground/go/funcc_test.go b/playground/go/funcc_test.go new file mode 100644 index 0000000..738454f --- /dev/null +++ b/playground/go/funcc_test.go @@ -0,0 +1,26 @@ +package main + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" +) + +func TestCow(t *testing.T) { + require.NoError(t, nil) + d := NewDog("Fibi", 4) + fmt.Println(d.name) + if d.name != "Fibi" { + t.Errorf("NewDog failled %v", d) + } +} + +func TestHorse(t *testing.T) { + d := NewDog("Fibi cat", 4) + fmt.Println(d.name) + if d.name != "Fibi cat" { + t.Errorf("NewDog failled %v", d) + + } +} diff --git a/playground/go/interface.go b/playground/go/interface.go new file mode 100644 index 0000000..8cde4fb --- /dev/null +++ b/playground/go/interface.go @@ -0,0 +1,67 @@ +package main + +import ( + "fmt" + "math" + //"math" +) + +type geometry interface { + area() float64 + perim() float64 +} + +type rect struct { + width float64 `-line:"width"` + height float64 `-line:"height"` +} + +type rect2 struct { + width int `yml:"width"` + height int `yml:"height"` +} + +func (r rect) area() float64 { + return r.width * r.height +} + +func (r rect) perim() float64 { + return 2*r.width + 2*r.height +} + +type circle struct { + radius float64 +} + +func (c circle) area() float64 { + return math.Pi * c.radius * c.radius +} + +func (c circle) perim() float64 { + return 2 * math.Pi * c.radius +} + +func measure(g geometry) int { + fmt.Println(g) + fmt.Println(g.area()) + fmt.Println(g.perim()) + return 1 +} + +func m2() { + measure(rect{width: 3}) +} + +func M2() { + measure(rect{width: 3}) +} + +func interfaceTest() { + r := rect{width: 3, height: 4} + c := circle{radius: 5} + measure(r) + measure(c) + d := circle{radius: 10} + fmt.Println() + fun2(d) +} diff --git a/playground/go/main.go b/playground/go/main.go new file mode 100644 index 0000000..26c075d --- /dev/null +++ b/playground/go/main.go @@ -0,0 +1,31 @@ +package main + +import ( + "errors" + "fmt" + "io/fs" + "unsafe" +) + +// main +// note: this is main func +func main() { + i := 32 + i = i + 1 + fmt.Println("hello, world", i) + var uns1 unsafe.Pointer + + var x struct { + a int64 + b bool + c string + } + const M, N = unsafe.Sizeof(x.c), unsafe.Sizeof(x) + fmt.Println(M, N, uns1) // 16 32 + + var perr *fs.PathError + if errors.As(nil, &perr) { + fmt.Println(perr.Path) + } + myfunc3("a", "b") +} diff --git a/playground/go/struct.go b/playground/go/struct.go new file mode 100644 index 0000000..47b8934 --- /dev/null +++ b/playground/go/struct.go @@ -0,0 +1,39 @@ +package main + +import "fmt" + +// import "fmt" + +type person struct { + name string + age int +} + +type say interface { + hello() string +} + +type strudent struct { + person struct { + name string + age int + } +} + +func newPerson(name string) *person { + p := person{name: name} + fmt.Println("") + p.age = 42 + return &p +} + +func newPerson2(name, say string) { + fmt.Println(name, say) +} + +func b() { + newPerson2("a", "say") + + ret := measure(rect{width: 3}) + fmt.Println(ret) +} diff --git a/playground/go/test/func.go b/playground/go/test/func.go new file mode 100644 index 0000000..8cadfaf --- /dev/null +++ b/playground/go/test/func.go @@ -0,0 +1,26 @@ +package test + +type Dog struct { + name string + age int + owner string +} + +func NewDog(name string, age int) *Dog { + return &Dog{name: name, age: age} +} + +// SetOwner +func (d *Dog) SetOwner(owner string) { + d.owner = owner +} + +// SetName +func (d *Dog) SetName(name string) { + if d == nil { + d = NewDog(name, 0) + d.name = name + } else { + d.name = name + } +} diff --git a/playground/go/test/func.tst b/playground/go/test/func.tst new file mode 100644 index 0000000..a7c777d --- /dev/null +++ b/playground/go/test/func.tst @@ -0,0 +1,26 @@ +package tekkkt + +type Dog kkktruct { + name kkktring + age int + owner kkktring +} + +func NewDog(name kkktring, age int) *Dog { + return &Dog{name: name, age: age} +} + +// kkketOwner +func (d *Dog) kkketOwner(owner kkktring) { + d.owner = owner +} + +// kkketName +func (d *Dog) kkketName(name kkktring) { + if d == nil { + d = NewDog(name, 0) + d.name = name + } elkkke { + d.name = name + } +} diff --git a/playground/go/test/func_test.go b/playground/go/test/func_test.go new file mode 100644 index 0000000..76d0c41 --- /dev/null +++ b/playground/go/test/func_test.go @@ -0,0 +1,22 @@ +package test + +import ( + "fmt" + "testing" +) + +func TestDog(t *testing.T) { + d := NewDog("Fibi", 4) + fmt.Println(d.name) + if d.name != "Fibi" { + t.Errorf("NewDog failled %v", d) + } +} + +func TestCat(t *testing.T) { + d := NewDog("Fibi cat", 4) + fmt.Println(d.name) + if d.name != "Fibi cat" { + t.Errorf("NewDog failled %v", d) + } +} diff --git a/playground/go/time.go b/playground/go/time.go new file mode 100644 index 0000000..190b725 --- /dev/null +++ b/playground/go/time.go @@ -0,0 +1,70 @@ +package main + +import ( + "fmt" + // "strings" + "time" + + log "github.com/sirupsen/logrus" +) + +// type Name2 struct { +// f1 string +// f2 int +// } +// +// type name4 struct { +// f1 string +// f2 int +// } +// +// type name5 struct { +// f1 string +// f2 int +// } +// +// func test2() { +// type some struct { +// Success bool `-line:"success"` +// Failure bool +// } +// +// // myfunc("aaa", "bbb") +// } + +func myfunc3(v, v2 string) error { + time.After(time.Hour) + fmt.Println(v, v2) + // fmt.Println(kk) + // + + time.Date(2020, 12, 11, 21, 11, 44, 12, nil) + time.Date(2020, 1, 11, 11, 11, 2, 1, nil) + time.Date(1111, 22, 11, 1, 1, 1, 1, nil) + time.Date(12345, 2333, 444, 555, 66, 1, 22, nil) + fmt.Println(`kkkkkk`) + log.Info(`abc`) + log.Infof(`log %s`, `def`) + log.Infof(`log %d`, 33) + + return nil +} + +// func myfunc4() { +// // myfunc("aaa", "bbb") // time.Date(12,11, ) +// // myfunc("abc", "def") +// // myfunc("1", "2") +// } +// +// func mytest2() { +// i := 1 +// log.Infof("%d", i) +// myfunc4() +// } +// +// func myfunc5() { +// hellostring := "hello" +// if strings.Contains(hellostring, "hello") { +// fmt.Println("it is there") +// } +// } diff --git a/playground/init.lua b/playground/init.lua new file mode 100644 index 0000000..4ec7e14 --- /dev/null +++ b/playground/init.lua @@ -0,0 +1,101 @@ +vim.cmd([[set runtimepath=$VIMRUNTIME]]) +vim.cmd([[set packpath=/tmp/nvim/site]]) + +local package_root = '/tmp/nvim/site/pack' +local install_path = package_root .. '/packer/start/packer.nvim' + +local function load_plugins() + require('packer').startup({ + function(use) + use({ 'wbthomason/packer.nvim' }) + use({ + 'nvim-treesitter/nvim-treesitter', + config = function() + require('nvim-treesitter.configs').setup({ + ensure_installed = { 'python', 'go', 'javascript' }, + highlight = { enable = true }, + }) + end, + run = ':TSUpdate', + }) + use({ 'neovim/nvim-lspconfig' }) + use({ 'ray-x/lsp_signature.nvim' }) + use({ 'ray-x/aurora' }) + use({ + 'ray-x/navigator.lua', + requires = { 'ray-x/guihua.lua', run = 'cd lua/fzy && make' }, + config = function() + require('navigator').setup({ + lsp_signature_help = true, + }) + end, + }) + use({ 'L3MON4D3/LuaSnip' }) + use({ + 'hrsh7th/nvim-cmp', + requires = { + 'hrsh7th/cmp-nvim-lsp', + 'saadparwaiz1/cmp_luasnip', + }, + config = function() + local cmp = require('cmp') + local luasnip = require('luasnip') + cmp.setup({ + snippet = { + expand = function(args) + require('luasnip').lsp_expand(args.body) + end, + }, + + mapping = { + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.confirm({ select = true }) + elseif luasnip.expand_or_locally_jumpable() then + luasnip.expand_or_jump() + else + fallback() + end + end, { 'i', 's' }), + }, + + sources = { + { name = 'nvim_lsp' }, + { name = 'buffer' }, + }, + }) + require('cmp').setup.cmdline(':', { + sources = { + { name = 'cmdline' }, + }, + }) + require('cmp').setup.cmdline('/', { + sources = { + { name = 'buffer' }, + }, + }) + end, + }) + end, + config = { + package_root = package_root, + compile_path = install_path .. '/plugin/packer_compiled.lua', + }, + }) +end + +if vim.fn.isdirectory(install_path) == 0 then + vim.fn.system({ + 'git', + 'clone', + 'https://github.com/wbthomason/packer.nvim', + install_path, + }) + load_plugins() + require('packer').sync() +else + load_plugins() +end + +vim.cmd('colorscheme aurora') diff --git a/playground/js/arrow.js b/playground/js/arrow.js new file mode 100644 index 0000000..f0f17bf --- /dev/null +++ b/playground/js/arrow.js @@ -0,0 +1,7 @@ +const sayHiToSomeone = (callback) => { + return callbcak(); +}; + +sayHiToSomeone(()=> { + console.log("aaa") +}) diff --git a/playground/js/closure.js b/playground/js/closure.js new file mode 100644 index 0000000..13991f3 --- /dev/null +++ b/playground/js/closure.js @@ -0,0 +1,12 @@ +function makeFunc() { + var browser = 'Mozilla'; + function displayName() { + alert(browser); + var message = 'hello ' + browser; + alert(message); + } + return displayName; +} + +var myFunc = makeFunc(); +myFunc(); diff --git a/playground/js/curry.js b/playground/js/curry.js new file mode 100644 index 0000000..db41c8d --- /dev/null +++ b/playground/js/curry.js @@ -0,0 +1,11 @@ +function curriedDot(vector1) { + return function(vector2) { + return vector1.reduce( + (sum, element, index) => (sum += element * vector2[index]), + 0 + ); + }; +} + +const sumElements = curriedDot([1, 1, 1]); +console.log() diff --git a/playground/js/date.js b/playground/js/date.js new file mode 100644 index 0000000..29cef40 --- /dev/null +++ b/playground/js/date.js @@ -0,0 +1 @@ +const time = new Date(12, 33, ) diff --git a/playground/js/test.js b/playground/js/test.js new file mode 100644 index 0000000..771ae57 --- /dev/null +++ b/playground/js/test.js @@ -0,0 +1,3 @@ +console.log("abc"); +var kingsglove = "abcdefg"; +console.log() diff --git a/playground/js/tsconfig.json b/playground/js/tsconfig.json new file mode 100644 index 0000000..e69de29 diff --git a/playground/py/hello.py b/playground/py/hello.py new file mode 100644 index 0000000..7b65d06 --- /dev/null +++ b/playground/py/hello.py @@ -0,0 +1,79 @@ +import math +import numpy as np +import os + +class Dog: + def __init__(self, name): + self.name = name + self.tricks = [] # creates a new empty list for each dog + + def add_trick(self, trick): + self.tricks.append(trick) + + +d = Dog('Fido') +d.add_trick('roll over') +print(d.tricks) + +def test_func(): + k = [1, 2, 3] + sum = 0 + for i in range(k, 1, 2): + sum += 1 + print(sum) + +def greet(greeting, name): + """ + This function greets to + the person passed in as + a parameter + """ + print(greeting + name + ". Good morning!") + + +# def greet(greeting, name, msg1, msg2): +# """ +# This function greets to +# the person passed in as +# a parameter +# """ +# print(greeting + name + ". Good morning!") + + +greet("a", "b") + + +def greet2(): + print("whatever") + + +def greet3(name): + greet2() + greet("hey", "dude", "", "") + print("whatever" + name) + +def greet3(): + pass + + +greet2() + +greet("name", "name") + +greet3("name") +greet3("") + +greet("1", "2") + + +def greeting(greet: int, *, g): + """ + This function greets to + the person passed in as + a parameter + """ + print(greet + g + ". Good morning!") + + +np.empty(1, order="F") +np.empty(1, order="F") diff --git a/playground/py/pd.py b/playground/py/pd.py new file mode 100644 index 0000000..924954d --- /dev/null +++ b/playground/py/pd.py @@ -0,0 +1,19 @@ +import pandas as pd +import io + + + + + + +pow() + + +arg = 111 +bufio = io +filename = 'my_excel.xls' + + + + +df = pd.read_excel(abc, defgh) diff --git a/playground/py/requirements.txt b/playground/py/requirements.txt new file mode 100644 index 0000000..e69de29