Skip to content

Commit

Permalink
Notifications (#55)
Browse files Browse the repository at this point in the history
* fix: respect notification setting for watch mode

* feat: have separate option for error notification
  • Loading branch information
afewyards authored Jul 7, 2024
1 parent 0673476 commit 5484100
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ By default, the plugin uses the default `tsc` command with the `--noEmit` flag t
run_as_monorepo = false,
bin_path = utils.find_tsc_bin(),
enable_progress_notifications = true,
enable_error_notifications = true,
flags = {
noEmit = true,
project = function()
Expand Down
22 changes: 14 additions & 8 deletions lua/tsc/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ end
--- @field run_as_monorepo boolean - (false) When true the `tsc` process will be started mode for each tsconfig in the current working directory
--- @field bin_path string - Path to the tsc binary if it is not in the projects node_modules or globally
--- @field enable_progress_notifications boolean - (true) When false progress notifications will not be shown
--- @field enable_error_notifications boolean - (true) When false error notifications will not be shown
--- @field hide_progress_notifications_from_history boolean - (true) When true progress notifications will be hidden from history
--- @field spinner string[] - ({"", "", "", "", "", "", "", ""}) - The spinner characters to use
--- @field pretty_errors boolean - (true) When true errors will be formatted with `pretty`
Expand All @@ -33,6 +34,7 @@ local DEFAULT_CONFIG = {
use_diagnostics = false,
bin_path = utils.find_tsc_bin(),
enable_progress_notifications = true,
enable_error_notifications = true,
run_as_monorepo = false,
flags = {
noEmit = true,
Expand Down Expand Up @@ -201,16 +203,18 @@ M.run = function()
end
end

if not config.enable_progress_notifications then
if #errors == 0 then
if config.enable_progress_notifications then
vim.notify(
format_notification_msg("Type-checking complete. No errors found 🎉"),
nil,
get_notify_options((notify_record and { replace = notify_record.id }))
)
end
return
end

if #errors == 0 then
vim.notify(
format_notification_msg("Type-checking complete. No errors found 🎉"),
nil,
get_notify_options((notify_record and { replace = notify_record.id }))
)
if not config.enable_error_notifications then
return
end

Expand Down Expand Up @@ -339,7 +343,9 @@ function M.setup(opts)
pattern = "*.{ts,tsx}",
desc = "Run tsc.nvim in watch mode automatically when saving a TypeScript file",
callback = function()
vim.notify("Type-checking your project via watch mode, hang tight 🚀", nil, get_notify_options())
if config.enable_progress_notifications then
vim.notify("Type-checking your project via watch mode, hang tight 🚀", nil, get_notify_options())
end
end,
})

Expand Down

0 comments on commit 5484100

Please sign in to comment.