1
Fork 0

Vscode snippets and other changes

This commit is contained in:
Matei Adriel 2022-08-05 20:11:10 +03:00
parent fecc007494
commit 4b3c896343
14 changed files with 366 additions and 147 deletions

View file

@ -0,0 +1,15 @@
local M = {}
function M.when(f)
if vim.g.vscode ~= nil then
f()
end
end
function M.unless(f)
if vim.g.vscode == nil then
f()
end
end
return M

View file

@ -6,6 +6,7 @@ function M.setup()
require("my.theme").setup()
require("my.options").setup()
require('my.keymaps').setup()
require('my.snippets').setup()
require('my.plugins').setup()
require("telescope.extensions.unicode").setupAbbreviations()
end

View file

@ -1,78 +1,91 @@
local M = {}
local function has_words_before()
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col,
col)
:match('%s') == nil
local line, col = unpack(vim.api.nvim_win_get_cursor(0))
return col ~= 0 and
vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col,
col)
:match('%s') == nil
end
function M.setup()
local cmp = require("cmp")
local lspkind = require('lspkind')
local luasnip = require("luasnip")
local cmp = require("cmp")
local lspkind = require('lspkind')
local luasnip = require("luasnip")
local options = {
formatting = {format = lspkind.cmp_format({mode = "symbol"})},
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
require('luasnip').lsp_expand(args.body)
end
},
mapping = {
['<C-b>'] = cmp.mapping(cmp.mapping.scroll_docs(-4), {'i', 'c'}),
['<C-f>'] = cmp.mapping(cmp.mapping.scroll_docs(4), {'i', 'c'}),
-- ['<C-Space>'] = cmp.mapping(cmp.mapping.complete(), {'i', 'c'}),
['<C-y>'] = cmp.config.disable,
['<C-e>'] = cmp.mapping({
i = cmp.mapping.abort(),
c = cmp.mapping.close()
}),
['<CR>'] = cmp.mapping.confirm({select = true}),
-- https://github.com/hrsh7th/nvim-cmp/wiki/Example-mappings
['<C-Space>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Insert,
select = true
},
-- TODO: abstract booth of those away perhaps?
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, {"i", "s"}),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, {"i", "s"})
},
sources = cmp.config.sources({
{name = 'nvim_lsp'}, -- lsp completion
{name = 'luasnip'} -- snippets
}, {{name = 'buffer'}})
local options = {
window = {
completion = {
winhighlight = "Normal:Pmenu,FloatBorder:Pmenu,Search:None",
col_offset = -3,
side_padding = 0,
},
},
formatting = {
fields = { "kind", "abbr", "menu" },
format = function(entry, vim_item)
local kind = lspkind.cmp_format({ mode = "symbol_text", maxwidth = 50 })(entry, vim_item)
local strings = vim.split(kind.kind, "%s", { trimempty = true })
kind.kind = " " .. strings[1] .. " "
kind.menu = " (" .. strings[2] .. ")"
return kind
end,
},
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
require('luasnip').lsp_expand(args.body)
end
},
mapping = {
["<Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_next_item()
elseif luasnip.expand_or_jumpable() then
luasnip.expand_or_jump()
elseif has_words_before() then
cmp.complete()
else
fallback()
end
end, { "i", "s" }),
["<S-Tab>"] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.select_prev_item()
elseif luasnip.jumpable(-1) then
luasnip.jump(-1)
else
fallback()
end
end, { "i", "s" }),
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' }, -- lsp completion
{ name = 'luasnip' } -- snippets
}, { { name = 'buffer' } })
}
cmp.setup(options)
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {
mapping = cmp.mapping.preset.cmdline(),
sources = {
{ name = 'buffer' }
}
})
cmp.setup(options)
-- Use buffer source for `/` (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline('/', {sources = {{name = 'buffer'}}})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
sources = cmp.config.sources({{name = 'path'}}, {{name = 'cmdline'}})
-- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
cmp.setup.cmdline(':', {
mapping = cmp.mapping.preset.cmdline(),
sources = cmp.config.sources({
{ name = 'path' }
}, {
{ name = 'cmdline' }
})
})
end
return M

View file

@ -1,30 +1,29 @@
local vscode = require("my.helpers.vscode")
local M = {}
function M.setup()
-- Other unconfigured plugins
require('nvim-autopairs').setup()
-- require("startup").setup()
require("presence"):setup({}) -- wtf does the : do here?
-- require("which-key").setup()
--
vscode.unless(function()
require("presence"):setup({})
require("my.plugins.dashboard").setup()
require("my.plugins.treesitter").setup()
require("my.plugins.cmp").setup()
require("my.plugins.lspconfig").setup()
require("my.plugins.null-ls").setup()
require("my.plugins.nvim-tree").setup()
require("my.plugins.vimtex").setup()
require("my.plugins.lean").setup()
end)
-- Plugins with their own configs:
require("my.plugins.vim-tmux-navigator").setup()
-- require("my.plugins.fzf-lua").setup()
-- require("my.plugins.nerdtree").setup()
require("my.plugins.treesitter").setup()
require("my.plugins.dashboard").setup()
require("my.plugins.cmp").setup()
require("my.plugins.lspconfig").setup()
require("my.plugins.null-ls").setup()
require("my.plugins.lualine").setup()
require("my.plugins.comment").setup()
require("my.plugins.nvim-tree").setup()
require("my.plugins.vimtex").setup()
require("my.plugins.telescope").setup()
require("my.plugins.vimux").setup()
-- require("my.plugins.idris").setup()
-- require("my.plugins.lh-brackets").setup()
require("my.plugins.lean").setup()
-- require("which-key").setup()
end
return M

View file

@ -0,0 +1,7 @@
local M = {}
function M.setup()
require("luasnip.loaders.from_vscode").lazy_load({})
end
return M

View file

@ -10,83 +10,83 @@ local utils = require "telescope.utils"
local add_abbreviations = false
local unicodeChars = {
nats = "",
rationals = "",
reals = "",
integers = "",
forall = "",
lambda = "λ",
arrow = "",
compose = "",
inverse = "⁻¹",
dots = "",
alpha = "ɑ",
beta = "β",
pi = "π",
Pi = 'Π',
sigma = "σ",
Sigma = "Σ",
tau = "τ",
theta = "θ",
gamma = "γ",
Gamma = "Γ",
context = "Γ"
nats = "",
rationals = "",
reals = "",
integers = "",
forall = "",
lambda = "λ",
arrow = "",
compose = "",
inverse = "⁻¹",
dots = "",
alpha = "ɑ",
beta = "β",
pi = "π",
Pi = 'Π',
sigma = "σ",
Sigma = "Σ",
tau = "τ",
theta = "θ",
gamma = "γ",
Gamma = "Γ",
context = "Γ"
}
-- our picker function for unicode chars
function M.picker(opts)
opts = opts or {}
local results = {}
opts = opts or {}
local results = {}
for key, value in pairs(unicodeChars) do
-- Name: char pair
table.insert(results, {key, value})
end
for key, value in pairs(unicodeChars) do
-- Name: char pair
table.insert(results, { key, value })
end
print(results)
print(results)
pickers.new(opts, {
prompt_title = "Unicode characters",
finder = finders.new_table {
results = results,
entry_maker = function(entry)
return {value = entry, display = entry[1], ordinal = entry[1]}
end
},
sorter = conf.generic_sorter(opts),
previewer = previewers.new {
preview_fn = function(_, entry) return entry.value[2] end
},
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
pickers.new(opts, {
prompt_title = "Unicode characters",
finder = finders.new_table {
results = results,
entry_maker = function(entry)
return { value = entry, display = entry[1], ordinal = entry[1] }
end
},
sorter = conf.generic_sorter(opts),
previewer = previewers.new {
preview_fn = function(_, entry) return entry.value[2] end
},
attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
if selection == nil then
utils.__warn_no_selection "my.abbreviations"
return
end
vim.api.nvim_put({selection.value[2]}, "", false, true)
vim.cmd("startinsert")
end)
return true
if selection == nil then
utils.__warn_no_selection "my.abbreviations"
return
end
}):find()
vim.api.nvim_put({ selection.value[2] }, "", false, true)
vim.cmd("startinsert")
end)
return true
end
}):find()
end
function M.setupAbbreviations(prefix, ending)
prefix = prefix or ""
ending = ending or ""
prefix = prefix or ""
ending = ending or ""
if not add_abbreviations then return end
if not add_abbreviations then return end
local abbreviate = require("my.abbreviations").abbr
local abbreviate = require("my.abbreviations").abbr
for key, value in pairs(unicodeChars) do
-- By default abbreviations are triggered using "_"
abbreviate(prefix .. key .. ending, value)
end
for key, value in pairs(unicodeChars) do
-- By default abbreviations are triggered using "_"
abbreviate(prefix .. key .. ending, value)
end
end
return M

View file

@ -3,8 +3,6 @@ set -g prefix C-a
unbind C-b
bind C-a send-prefix
teh
# don't rename windows automatically
set-option -g allow-rename off

View file

@ -0,0 +1,3 @@
# Vscode snippets
These are snippets usable both in vscode and neovim, defined in vscode format.

View file

@ -0,0 +1,22 @@
{
"name": "adriels-snippets",
"engines": {
"vscode": "^1.11.0"
},
"contributes": {
"snippets": [
{
"language": ["purs", "purescript"],
"path": "./snippets/purescript/other.json"
},
{
"language": ["purs", "purescript"],
"path": "./snippets/purescript/imports.json"
},
{
"language": ["purs", "purescript"],
"path": "./snippets/purescript/deriving.json"
}
]
}
}

View file

@ -0,0 +1,59 @@
{
"Derive newtype instance": {
"prefix": "nderive",
"description": "Use newtype deriving on any typeclass",
"body": "derive newtype instance $0 $3 $2"
},
"Generate json instances": {
"prefix": "json",
"description": "Generate the deriving of the EncodeJson and DecodeJson typeclasses",
"body": [
"derive newtype instance EncodeJson $1",
"derive newtype instance DecodeJson $1"
]
},
"Generic": {
"prefix": "generic",
"description": "Generate the generic instance for a type",
"body": "derive instance Generic $1 _"
},
"Generic Show": {
"prefix": "gshow",
"description": "Generate generic show instances",
"body": [
"instance Show $1 where",
" show = genericShow"
]
},
"Generic Debug": {
"prefix": "gdebug",
"description": "Generate generic debug instances",
"body": [
"instance Debug $1 where",
" debug = genericDebug"
]
},
"Generic json": {
"prefix": "gjson",
"description": "Generate generic json instances",
"body": [
"instance EncodeJson $1 where",
" encodeJson = genericEncodeJson",
"instance DecodeJson $1 where",
" decodeJson = genericDecodeJson"
]
},
"Instance": {
"prefix": "instance",
"description": "Declare typeclass instance",
"body": [
"instance $2 $3 where",
" $0"
]
},
"Functor": {
"prefix": "functor",
"description": "Derive a Functor instance",
"body": "derive instance Functor $1$0"
}
}

View file

@ -0,0 +1,37 @@
{
"Tuple constructors": {
"prefix": "imptuple",
"description": "Import tuple constructors",
"body": "import Data.Tuple.Nested (type (/\\), (/\\))"
},
"Map": {
"prefix": "impmap",
"description": "Import Map module",
"body": "import Data.Map as Map"
},
"HashMap": {
"prefix": "imphashmap",
"description": "Import HashMap module",
"body": "import Data.HashMap as HashMap"
},
"FRP Event": {
"prefix": "impevent",
"description": "Import FRP.Event module",
"body": "import FRP.Event as E"
},
"List": {
"prefix": "implist",
"description": "Import List module",
"body": "import Data.List as List"
},
"Array": {
"prefix": "imparray",
"description": "import Array module",
"body": "import Data.Array as Array"
},
"AVar": {
"prefix": "impavar",
"description": "import AVar module",
"body": "import Effect.Aff.AVar as AV"
}
}

View file

@ -0,0 +1,64 @@
{
"Definition": {
"prefix": "definition",
"description": "Basic purescript definition",
"body": [
"$1 :: $2",
"$1 = $3"
]
},
"SProxy": {
"prefix": "sproxy",
"description": "Generate a proxy constant",
"body": [
"_$1 :: Proxy \"$1\"",
"_$1 = Proxy"
]
},
"Proxy": {
"prefix": "proxy",
"description": "Generate a proxy constant",
"body": [
"_$1 :: Proxy $1",
"_$1 = Proxy"
]
},
"Prop": {
"prefix": "prop",
"description": "Prop lens",
"body": [
"_$1 :: Lens' $2 $3",
"_$1 = prop (Proxy :: _ \"$1\")"
]
},
"Variant constructor": {
"prefix": "inj",
"description": "Generate a constructor for a variant an inline sproxy",
"body": [
"$1 :: forall r a. a -> Variant ( $1 :: a | r)",
"$1 = inj (SProxy :: SProxy \"$1\")"
]
},
"Full variant constructor": {
"prefix": "injf",
"description": "Generate a constructor for a variant with an external sproxy definition",
"body": [
"$1 :: forall r a. a -> Variant ( $1 :: a | r)",
"$1 = inj _$1",
"",
"_$1 :: Proxy \"$1\"",
"_$1 = Proxy"
]
},
"Example code": {
"prefix": "ex",
"description": "Provide example usage for some piece of code",
"body" : [
"-- |",
"-- | Ex:",
"-- | ```purs",
"-- | $0",
"-- | ```"
]
}
}

View file

@ -34,7 +34,7 @@
# editors
# vscodium
# vscode
vscode
# vim
# emacs
vimclip # use neovim anywhere
@ -45,7 +45,7 @@
signal-desktop
tdesktop # telegram for the desktop
# deluge
# zoom-us
zoom-us
# teams
# browsers

View file

@ -42,6 +42,7 @@ let
myConfig = ''
vim.g.lualineTheme = "${theme.neovim.lualineTheme}"
vim.opt.runtimepath:append("${paths.dotfiles}/neovim")
vim.opt.runtimepath:append("${paths.dotfiles}/vscode-snippets")
require("my.init").setup()
'';