diff --git a/README.md b/README.md index 83d23d5..fa8271f 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ Checking following in order. b. Shebang is present and including `deno` -> **deno** 4. Otherwise, nothing is detected. +## Optional: To suppress errors on switching to node + +To suppress errors what you'll see when switching to node, you should use [my patched coc-deno](https://github.com/LumaKernel/coc-deno-pruned) (not published to npm, so you should install as vim script and build) instead of official until [the issue](https://github.com/fannheyward/coc-deno/issues/184) is fixed. + ## When does this try to detect? This tries to detect when following events occurred. diff --git a/src/commands.ts b/src/commands.ts index 912ca3b..9f815f8 100644 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,5 +1,4 @@ import { commands, window, workspace } from 'coc.nvim'; -import { ConfigurationTarget } from './coc_internal'; import { setConfigWorkspace } from './set_config'; import type { Settings, TsRuntime } from './settings'; import { getSettings } from './settings'; @@ -7,7 +6,6 @@ import { getSettings } from './settings'; const configure = async (runtime: TsRuntime, settings: Settings): Promise => { await setConfigWorkspace('tsserver', 'enable', runtime === 'node'); await setConfigWorkspace('deno', 'enable', runtime === 'deno'); - await commands.executeCommand('editor.action.restart'); const override = runtime === 'node' ? settings.nodeOverride : settings.denoOverride; /* eslint-disable no-restricted-syntax,no-await-in-loop,no-continue */ @@ -21,6 +19,7 @@ const configure = async (runtime: TsRuntime, settings: Settings): Promise await setConfigWorkspace(ns.join('.'), nsKey, override[key]); } /* eslint-enable no-restricted-syntax,no-await-in-loop,no-continue */ + await commands.executeCommand('editor.action.restart'); }; export const manualInitializeWorkspace = async (runtime: TsRuntime): Promise => { @@ -29,15 +28,13 @@ export const manualInitializeWorkspace = async (runtime: TsRuntime): Promise => { - const workspaceConfigFile = workspace.getConfigFile(ConfigurationTarget.Workspace); + const configuration = workspace.getConfiguration(); const settings = getSettings(); - const exists = typeof workspaceConfigFile === 'string'; + const exists = configuration.has(''); if (settings.doNothingIfConfigExists && exists) return; if (settings.doNotCreateOnNode && runtime === 'node' && !exists) return; @@ -49,6 +46,6 @@ export const autoInitializeWorkspace = async (runtime: TsRuntime): Promise if (exists && denoConfig.get('enable') && runtime === 'deno') return; await configure(runtime, settings); - await commands.executeCommand('editor.action.restart'); + await workspace.nvim.command(`doautocmd User tsdetect#coc#auto#switch#${runtime}#after`); }; diff --git a/src/globals.d.ts b/src/globals.d.ts deleted file mode 100644 index 88e0e2e..0000000 --- a/src/globals.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -declare module 'coc.nvim' { - import type { ConfigurationTarget } from './coc_internal'; - - export namespace workspace { - export function getConfigFile(target: ConfigurationTarget): string | undefined; - } -}