fix: darwin spotlight patch; extra: debugging neovim-cmp type

std
Hung 2023-06-15 12:46:01 -07:00
parent f04388f562
commit e67a18e465
7 changed files with 128 additions and 47 deletions

View File

@ -62,11 +62,11 @@
"utils": "utils"
},
"locked": {
"lastModified": 1685948350,
"narHash": "sha256-1FldJ059so0X/rScdbIiOlQbjjSNCCTdj2cUr5pHU4A=",
"lastModified": 1686747123,
"narHash": "sha256-XUQK9kwHpTeilHoad7L4LjMCCyY13Oq383CoFADecRE=",
"owner": "serokell",
"repo": "deploy-rs",
"rev": "65211db63ba1199f09b4c9f27e5eba5ec50d76ac",
"rev": "724463b5a94daa810abfc64a4f87faef4e00f984",
"type": "github"
},
"original": {
@ -301,11 +301,11 @@
"paisano": "paisano"
},
"locked": {
"lastModified": 1686502488,
"narHash": "sha256-sLSiDkU9oNpcl1QEge0xVviD7N87iVdrwl7l9i+6mxQ=",
"lastModified": 1686781920,
"narHash": "sha256-1KHvvV2qcypAC6Zn+7HL+VxOuVttB3Iqrp/kDwLbqiI=",
"owner": "divnix",
"repo": "hive",
"rev": "e8b46fa4d2917dfd456f3f040e9761262b4648d2",
"rev": "a057e2df518c7ecb0dd14bd42661dc11129609c4",
"type": "github"
},
"original": {
@ -504,11 +504,11 @@
},
"nixpkgs_3": {
"locked": {
"lastModified": 1686501370,
"narHash": "sha256-G0WuM9fqTPRc2URKP9Lgi5nhZMqsfHGrdEbrLvAPJcg=",
"lastModified": 1686592866,
"narHash": "sha256-riGg89eWhXJcPNrQGcSwTEEm7CGxWC06oSX44hajeMw=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "75a5ebf473cd60148ba9aec0d219f72e5cf52519",
"rev": "0eeebd64de89e4163f4d3cf34ffe925a5cf67a05",
"type": "github"
},
"original": {

View File

@ -1,5 +1,4 @@
-- What: Mono-file nvim configuration file Why: Easy to see through everything without needing to navigate thru files Features:
-- - LSP
-- What: Mono-file nvim configuration file Why: Easy to see through everything without needing to navigate thru files Features: - LSP
-- - Auto-complete (in insert mode: ctrl-space, navigate w/ Tab+S-Tab, confirm: Enter)
-- - <leader>df to format document
-- - Harpoon marks: Navigate through main files within each project
@ -29,10 +28,12 @@ for _, path in ipairs(vim.api.nvim_list_runtime_paths()) do
end
end
local wplug_log = require('plenary.log').new({ plugin = 'wplug_log', level = 'debug', use_console = false })
-- Do Plug if plugin not yet linked in `rtp`. This takes care of Nix-compatibility
local function WPlug(plugin_path, ...)
local plugin_name = string.lower(plugin_path:match("/([^/]+)$"))
if not installed_plugins[plugin_name] then
wplug_log.info("Plugging " .. plugin_path)
Plug(plugin_path, ...)
end
end
@ -262,6 +263,7 @@ vim.opt.listchars:append "eol:↴"
require("indent_blankline").setup {
show_end_of_line = true,
space_char_blankline = " ",
}
-- User command that transform into 2-spaces by translating to tabstop
vim.api.nvim_create_user_command(
@ -535,7 +537,7 @@ require("inlay-hints").setup {
-- renderer to use
-- possible options are dynamic, eol, virtline and custom
-- renderer = "inlay-hints/render/dynamic",
renderer = "inlay-hints/render/dynamic",
renderer = "inlay-hints/render/eol",
hints = {
parameter = {
@ -637,6 +639,42 @@ cmp.event:on(
)
---@alias EntryFilter {id: integer, compe: lsp.CompletionItem, return_type: string, return_type2: string, score: number, label: string, source_name: string, bufnr: number?, offset: number?, kind: lsp.CompletionItemKind }
---@param entry cmp.Entry
---@return EntryFilter
local function entry_filter_sync(entry)
local compe = entry:get_completion_item()
local return_type = compe.data and compe.data.return_type
local return_type2 = compe.detail
local score = entry.score
local label = compe.label
local source_name = entry.source.name
local bufnr = entry.context.bufnr
local offset = entry:get_offset()
local kind = entry:get_kind()
local id = entry.id
return {
id = id,
compe = compe,
return_type = return_type,
return_type2 = return_type2,
score = score,
label = label,
source_name = source_name,
bufnr = bufnr,
offset = offset,
kind = kind,
}
end
---@param entry cmp.Entry
---@param callback fun(entry: EntryFilter): any
local function entry_filter(entry, callback)
entry:resolve(function()
callback(entry_filter_sync(entry))
end)
end
---@type cmp.ConfigSchema
local cmp_config = {
snippet = {
@ -645,7 +683,7 @@ local cmp_config = {
end,
},
mapping = cmp.mapping.preset.insert {
['<C-l'] = cmp.mapping(function(_)
['<C-l'] = cmp.mapping(function(fallback)
if cmp.visible() then
cmp.refresh()
else
@ -706,16 +744,25 @@ local cmp_config = {
}
}
vim_item = kind_fn(entry, vim_item)
-- copium that this will force resolve for entry
entry_filter(entry, function(entry)
if entry.source_name == "nvim_lsp" then
log.debug('format:entry: ' .. vim.inspect(entry, { depth = 2 }))
end
end)
return require('tailwindcss-colorizer-cmp').formatter(entry, vim_item)
end,
},
sources = cmp.config.sources( --[[@as cmp.SourceConfig[]] {
{ name = 'nvim_lsp', },
{ name = 'nvim_lsp', max_item_count = 30, },
{ name = 'nvim_lsp_signature_help' },
-- NOTE: Path is triggered by `.` and `/`, so when it comes up, it's
-- usually desirable.
{ name = 'path' },
{ name = 'luasnip' },
{ name = 'path', max_item_count = 20, },
{ name = 'luasnip', max_item_count = 20, },
{
name = 'buffer',
option = {
@ -733,7 +780,8 @@ local cmp_config = {
return vim.tbl_keys(bufs)
end,
},
},
max_item_count = 20,
}
-- NOTE: I don't like cmdline that much. Most of the time, it recommends more harm than good
-- { name = 'cmp_tabnine' },
-- { name = "conjure" },
@ -741,11 +789,6 @@ local cmp_config = {
experimental = { ghost_text = { hl_group = "Comment" }, },
sorting = {
comparators = {
---@param lhs_entry cmp.Entry
---@param rhs_entry cmp.Entry
function(lhs_entry, rhs_entry)
return nil
end,
cmp.config.compare.exact,
cmp.config.compare.recently_used,
cmp.config.compare.offset,
@ -760,6 +803,9 @@ local cmp_config = {
cmp.setup(vim.tbl_deep_extend("force", require('cmp.config.default')(), cmp_config))
-- set max autocomplete height. this prevents huge recommendations to take over the screen
vim.o.pumheight = 15 -- 15/70 is good enough ratio for me. I generally go with 80-90 max height, though
vim.o.pumblend = 15 -- semi-transparent for the art, nothing too useful
-- `/` cmdline search.
cmp.setup.cmdline('/', {
@ -818,7 +864,7 @@ require("mason").setup({
})
require('mason-lspconfig').setup({
-- ensure_installed = servers,
ensure_installed = { "pylsp", "pyright", "tailwindcss", "svelte", "astro", "lua_ls" },
ensure_installed = { "pylsp", "pyright", "tailwindcss", "svelte", "astro", "lua_ls", "tsserver" },
automatic_installation = false,
})
@ -1277,7 +1323,7 @@ vim.api.nvim_create_user_command('ShowLogs', function(opts)
local file = io.open(logfile, 'r')
if not file then
print(string.format("No logfile found for plugin '%s'", vim.inspect(plugin_name)))
print("min_level: " .. vim.inspect(min_level))
print("Attempted paths: %s", vim.inspect(logfile))
return
end
file:close()

View File

@ -1,8 +1,15 @@
# This patch exists since Darwin's search bar requires solid apps and not
# symlinked
# TODO: QA
# - [x] works for base case
# - [x] works for repeated case
# - [ ] works after base case, then removed
# - [ ] works for repeated case, then removed
{ lib, pkgs, config, ... }:
{
# Copy GUI apps to "~/Applications/Home Manager Apps"
# Based on this comment: https://github.com/nix-community/home-manager/issues/1341#issuecomment-778820334
home.activation.darwinApps =
home.activation.patch-spotlight =
if pkgs.stdenv.isDarwin then
let
apps = pkgs.buildEnv {
@ -11,7 +18,7 @@
pathsToLink = "/Applications";
};
in
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
lib.hm.dag.entryAfter [ "linkGeneration" ] ''
# Install MacOS applications to the user environment.
HM_APPS="$HOME/Applications/Home Manager Apps"
# Reset current state
@ -27,4 +34,17 @@
''
else
"";
# We need this in case upstream home-manager changes the behavior of linking
# applications
home.activation.remove-patch-spotlight =
if pkgs.stdenv.isDarwin then
lib.hm.dag.entryBefore [ "checkLinkTargets" ] ''
HM_APPS="$HOME/Applications/Home Manager Apps"
# Reset current state
if [ -e "$HM_APPS" ]; then
$DRY_RUN_CMD mv "$HM_APPS" "$HM_APPS.$(date +%Y%m%d%H%M%S)"
fi
''
else
"";
}

View File

@ -818,11 +818,11 @@
]
},
"locked": {
"lastModified": 1686638670,
"narHash": "sha256-+/5lqVzqeOguJlX/57LU2e3tChw5L/jpAOzyNsiveVg=",
"lastModified": 1686852570,
"narHash": "sha256-Hzufya/HxjSliCwpuLJCGY0WCQajzcpsnhFGa+TCkCM=",
"owner": "nix-community",
"repo": "home-manager",
"rev": "c8dafb187b7b010bf279a7bf0842eaadf3e387a8",
"rev": "4e09c83255c5b23d58714d56672d3946faf1bcef",
"type": "github"
},
"original": {
@ -953,11 +953,11 @@
"topiary": "topiary"
},
"locked": {
"lastModified": 1686564419,
"narHash": "sha256-DJGvo1wDBRQSjAHAiNb8dD/77/CHwpeBzBYasIb51Hk=",
"lastModified": 1686837312,
"narHash": "sha256-/izfKcPXT/Y4N8zgAncPp7ov5Qb39J3p74FaNsLUk/c=",
"owner": "tweag",
"repo": "nickel",
"rev": "25c509e0b19f5b38b61a28765f62ce5c20e3e476",
"rev": "6f424fd5f8e9c5bcdc07d855427d3dce14cd247e",
"type": "github"
},
"original": {
@ -1037,11 +1037,11 @@
]
},
"locked": {
"lastModified": 1686574167,
"narHash": "sha256-hxE8z+S9E4Qw03D2VQRaJUmj9zep3FvhKz316JUZuPA=",
"lastModified": 1686740472,
"narHash": "sha256-b668DY2qGdBCUwIkk6Z32bcpCsUISQJrEEvhtn1gGgY=",
"owner": "mic92",
"repo": "nix-index-database",
"rev": "7e83b70f31f4483c07e6939166cb667ecb8d05d5",
"rev": "e11c61073b777e025993c5ef63ddbf776a9cca15",
"type": "github"
},
"original": {
@ -1114,6 +1114,21 @@
"type": "github"
}
},
"nixpkgs-latest": {
"locked": {
"lastModified": 1686856014,
"narHash": "sha256-3V2uo9xR7jMJLimzVGj7DO7qYwvZbf02UaXFIP3k0IE=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "7a53daed2a71fd4b7b177bc48f2f9c996a5bb4b2",
"type": "github"
},
"original": {
"owner": "nixos",
"repo": "nixpkgs",
"type": "github"
}
},
"nixpkgs-lib": {
"locked": {
"dir": "lib",
@ -1197,11 +1212,11 @@
},
"nixpkgs_12": {
"locked": {
"lastModified": 1686501370,
"narHash": "sha256-G0WuM9fqTPRc2URKP9Lgi5nhZMqsfHGrdEbrLvAPJcg=",
"lastModified": 1686592866,
"narHash": "sha256-riGg89eWhXJcPNrQGcSwTEEm7CGxWC06oSX44hajeMw=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "75a5ebf473cd60148ba9aec0d219f72e5cf52519",
"rev": "0eeebd64de89e4163f4d3cf34ffe925a5cf67a05",
"type": "github"
},
"original": {
@ -1565,6 +1580,7 @@
"nix-index-database": "nix-index-database",
"nixgl": "nixgl",
"nixpkgs": "nixpkgs_12",
"nixpkgs-latest": "nixpkgs-latest",
"rust-overlay": "rust-overlay_8"
}
},
@ -1768,11 +1784,11 @@
"nixpkgs": "nixpkgs_13"
},
"locked": {
"lastModified": 1686623191,
"narHash": "sha256-x2gQcKtSgfbZlcTaVvdMPbrXMRjUEYIV88yzsFww6D4=",
"lastModified": 1686795910,
"narHash": "sha256-jDa40qRZ0GRQtP9EMZdf+uCbvzuLnJglTUI2JoHfWDc=",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "e279547de84413ca1a65cec3f0f879709c8c65eb",
"rev": "5c2b97c0a9bc5217fc3dfb1555aae0fb756d99f9",
"type": "github"
},
"original": {

View File

@ -181,7 +181,7 @@
modules = base.modules ++ [
./home.nix
./base/productive_desktop.nix
# ./base/darwin-spotlight.nix
./base/darwin-spotlight.nix
{
base.private_chromium.enable = false;
}
@ -190,8 +190,6 @@
base.graphics.enable = false;
# don't want to deal with GL stuffs on mac yet :/
base.graphics.useNixGL.defaultPackage = null;
# FIXME: this actually does not exist
# base.keepass.path = "/Users/htran/keepass.kdbx";
base.alacritty.font.size = 11.0;
base.git.name = "Hung";
base.git.email = "htran@egihosting.com";

View File

@ -66,7 +66,7 @@ let
});
vimPlugins = (final: prev: {
inherit (nixpkgs-latest) vimPlugins;
inherit (nixpkgs-latest.legacyPackages.${system}) vimPlugins;
});
in
[
@ -77,4 +77,5 @@ in
rust
kpcli-py
nickel
vimPlugins
]

View File

@ -35,9 +35,9 @@ nix flake update "${SCRIPT_DIR}/../nix-conf/home-manager"
# test if we have home-manager, if not, attempt to use nix to put home-manager to
# our environment
if ! command -v home-manager ; then
nix-shell -p home-manager --run "home-manager switch --flake $HOME_MANAGER_DIR $@"
nix-shell -p home-manager --run "home-manager switch -b backup --flake $HOME_MANAGER_DIR $@"
else
home-manager switch --flake "$HOME_MANAGER_DIR" $@
home-manager switch -b backup --flake "$HOME_MANAGER_DIR" $@
fi