tsc.nvim
tsc.nvim copied to clipboard
Unsure where to put this but for those of us using NX, you need a custom matcher for tsConfig.base.json and tsConfig.app.json
This works:
local function find_closest_file(match_strings, start_dir, depth)
-- Initialize depth if not provided
depth = depth or 0
-- Maximum depth to prevent infinite recursion
local max_depth = 10
-- Determine the starting directory: current buffer's directory or provided start_dir
start_dir = start_dir or vim.fn.expand('%:p:h') or vim.fn.getcwd()
-- Log the attempt and depth
-- Base case: if maximum depth is reached, stop the search
if depth > max_depth then
return nil
end
-- Iterate over the array of match strings and construct the find command
for _, match_string in ipairs(match_strings) do
local command = string.format("find '%s' -type f -name '*%s*' -maxdepth 1", start_dir, match_string)
local handle = io.popen(command)
local result = handle:read("*a")
handle:close()
-- Split the result into lines (files)
local files = {}
for line in result:gmatch("[^\r\n]+") do
table.insert(files, line)
end
-- If a file is found, return its path
if #files > 0 then
return files[1] -- Return the first matching file path
end
end
-- No file found, move to the parent directory and repeat the search
local parent_dir = vim.fn.fnamemodify(start_dir, ':h')
if parent_dir == start_dir then
-- If the parent directory is the same as the current directory, we're at the root
return nil
else
-- Recursive call to search in the parent directory, incrementing the depth
return find_closest_file(match_strings, parent_dir, depth + 1)
end
end
return find_closest_file
-----EXAMPLE USEAGE------ local find_closest_file = require("path-from-lua-root-to-the-file-where-you-saved-the-above-function") local output = find_closest_file({'tsConfig.app.json', tsConfig.base.json'}) return output in your 'project' function
profit
Sweet this look good to me, it's been a few years since I've used Nx, but i'd be more than happy to accept a pr for this - or if you could even provide a Nx repo where TSC does not work that I could test on