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.theme").setup()
require("my.options").setup() require("my.options").setup()
require('my.keymaps').setup() require('my.keymaps').setup()
require('my.snippets').setup()
require('my.plugins').setup() require('my.plugins').setup()
require("telescope.extensions.unicode").setupAbbreviations() require("telescope.extensions.unicode").setupAbbreviations()
end end

View file

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

View file

@ -1,30 +1,29 @@
local vscode = require("my.helpers.vscode")
local M = {} local M = {}
function M.setup() function M.setup()
-- Other unconfigured plugins
require('nvim-autopairs').setup() require('nvim-autopairs').setup()
-- require("startup").setup() --
require("presence"):setup({}) -- wtf does the : do here? vscode.unless(function()
-- require("which-key").setup() 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.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.lualine").setup()
require("my.plugins.comment").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.telescope").setup()
require("my.plugins.vimux").setup() require("my.plugins.vimux").setup()
-- require("my.plugins.idris").setup() -- require("my.plugins.idris").setup()
-- require("my.plugins.lh-brackets").setup() -- require("which-key").setup()
require("my.plugins.lean").setup()
end end
return M 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 add_abbreviations = false
local unicodeChars = { local unicodeChars = {
nats = "", nats = "",
rationals = "", rationals = "",
reals = "", reals = "",
integers = "", integers = "",
forall = "", forall = "",
lambda = "λ", lambda = "λ",
arrow = "", arrow = "",
compose = "", compose = "",
inverse = "⁻¹", inverse = "⁻¹",
dots = "", dots = "",
alpha = "ɑ", alpha = "ɑ",
beta = "β", beta = "β",
pi = "π", pi = "π",
Pi = 'Π', Pi = 'Π',
sigma = "σ", sigma = "σ",
Sigma = "Σ", Sigma = "Σ",
tau = "τ", tau = "τ",
theta = "θ", theta = "θ",
gamma = "γ", gamma = "γ",
Gamma = "Γ", Gamma = "Γ",
context = "Γ" context = "Γ"
} }
-- our picker function for unicode chars -- our picker function for unicode chars
function M.picker(opts) function M.picker(opts)
opts = opts or {} opts = opts or {}
local results = {} local results = {}
for key, value in pairs(unicodeChars) do for key, value in pairs(unicodeChars) do
-- Name: char pair -- Name: char pair
table.insert(results, {key, value}) table.insert(results, { key, value })
end end
print(results) print(results)
pickers.new(opts, { pickers.new(opts, {
prompt_title = "Unicode characters", prompt_title = "Unicode characters",
finder = finders.new_table { finder = finders.new_table {
results = results, results = results,
entry_maker = function(entry) entry_maker = function(entry)
return {value = entry, display = entry[1], ordinal = entry[1]} return { value = entry, display = entry[1], ordinal = entry[1] }
end end
}, },
sorter = conf.generic_sorter(opts), sorter = conf.generic_sorter(opts),
previewer = previewers.new { previewer = previewers.new {
preview_fn = function(_, entry) return entry.value[2] end preview_fn = function(_, entry) return entry.value[2] end
}, },
attach_mappings = function(prompt_bufnr) attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function() actions.select_default:replace(function()
actions.close(prompt_bufnr) actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry() local selection = action_state.get_selected_entry()
if selection == nil then if selection == nil then
utils.__warn_no_selection "my.abbreviations" utils.__warn_no_selection "my.abbreviations"
return return
end
vim.api.nvim_put({selection.value[2]}, "", false, true)
vim.cmd("startinsert")
end)
return true
end end
}):find()
vim.api.nvim_put({ selection.value[2] }, "", false, true)
vim.cmd("startinsert")
end)
return true
end
}):find()
end end
function M.setupAbbreviations(prefix, ending) function M.setupAbbreviations(prefix, ending)
prefix = prefix or "" prefix = prefix or ""
ending = ending 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 for key, value in pairs(unicodeChars) do
-- By default abbreviations are triggered using "_" -- By default abbreviations are triggered using "_"
abbreviate(prefix .. key .. ending, value) abbreviate(prefix .. key .. ending, value)
end end
end end
return M return M

View file

@ -3,8 +3,6 @@ set -g prefix C-a
unbind C-b unbind C-b
bind C-a send-prefix bind C-a send-prefix
teh
# don't rename windows automatically # don't rename windows automatically
set-option -g allow-rename off 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 # editors
# vscodium # vscodium
# vscode vscode
# vim # vim
# emacs # emacs
vimclip # use neovim anywhere vimclip # use neovim anywhere
@ -45,7 +45,7 @@
signal-desktop signal-desktop
tdesktop # telegram for the desktop tdesktop # telegram for the desktop
# deluge # deluge
# zoom-us zoom-us
# teams # teams
# browsers # browsers

View file

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