Skip to content

Commit df8b125

Browse files
authored
👍 show constraint error warning (#404)
* 👍 show constraint error warning * 👍 simplify detecting the error message * 🌿 clarify test issue
1 parent f5bcc4f commit df8b125

File tree

4 files changed

+75
-1
lines changed

4 files changed

+75
-1
lines changed

autoload/denops/_internal/server/proc.vim

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,21 @@ function! s:on_exit(options, status) abort
9696
let s:job = v:null
9797
call denops#_internal#echo#debug(printf('Server stopped: %s', a:status))
9898
call denops#_internal#event#emit(printf('DenopsSystemProcessStopped:%s', a:status))
99+
const l:last_error = execute('20messages')
100+
if l:last_error =~# 'Could not find constraint\|Could not find version of'
101+
" Show a warning message when Deno module cache issue is detected
102+
" https://github.com/vim-denops/denops.vim/issues/358
103+
call denops#_internal#echo#warn(repeat('*', 80))
104+
call denops#_internal#echo#warn('Deno module cache issue is detected.')
105+
call denops#_internal#echo#warn(
106+
\ "Execute 'call denops#cache#update(#{reload: v:true})' and restart Vim/Neovim."
107+
\ )
108+
call denops#_internal#echo#warn(
109+
\ 'See https://github.com/vim-denops/denops.vim/issues/358 for more detail.'
110+
\ )
111+
call denops#_internal#echo#warn(repeat('*', 80))
112+
return
113+
endif
99114
if s:job isnot# v:null || !a:options.restart_on_exit || s:stopped_on_purpose || s:exiting
100115
return
101116
endif

deno.jsonc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"apply:supported-versions": "deno run --allow-read --allow-write .scripts/apply_supported_versions.ts"
1111
},
1212
"exclude": [
13-
".coverage/"
13+
".coverage/",
14+
"tests/denops/testdata/no_check/"
1415
],
1516
// NOTE: Import maps should only be used from test modules.
1617
"imports": {

tests/denops/runtime/functions/server_test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import {
33
assertEquals,
44
assertFalse,
55
assertMatch,
6+
assertNotMatch,
67
assertRejects,
8+
assertStringIncludes,
79
} from "jsr:@std/assert@^1.0.1";
810
import { delay } from "jsr:@std/async@^0.224.0/delay";
911
import { AsyncDisposableStack } from "jsr:@nick/dispose@^1.1.0/async-disposable-stack";
@@ -489,6 +491,56 @@ testHost({
489491
);
490492
});
491493
});
494+
495+
await t.step(
496+
"if the server is stopped with a constraint error (issue 401)",
497+
async (t) => {
498+
await using stack = new AsyncDisposableStack();
499+
stack.defer(async () => {
500+
await host.call("denops#server#stop");
501+
await wait(
502+
() => host.call("eval", "denops#server#status() ==# 'stopped'"),
503+
);
504+
});
505+
506+
outputs = [];
507+
await host.call("execute", [
508+
"silent! unlet g:__test_denops_process_stopped_fired",
509+
`let g:denops#server#deno_args = ['${
510+
resolve("no_check/cli_constraint_error_on_issue_401.ts")
511+
}']`,
512+
"let g:denops#server#restart_delay = 1000",
513+
"let g:denops#server#restart_interval = 10000",
514+
"let g:denops#server#restart_threshold = 1",
515+
"call denops#server#start()",
516+
], "");
517+
518+
await t.step("fires DenopsProcessStopped", async () => {
519+
await wait(() =>
520+
host.call("exists", "g:__test_denops_process_stopped_fired")
521+
);
522+
});
523+
524+
await t.step("changes status to 'stopped' asynchronously", async () => {
525+
assertEquals(await host.call("denops#server#status"), "stopped");
526+
});
527+
528+
await t.step("outputs warning message", async () => {
529+
await delay(MESSAGE_DELAY);
530+
assertStringIncludes(
531+
outputs.join(""),
532+
"Execute 'call denops#cache#update(#{reload: v:true})' and restart Vim/Neovim.",
533+
);
534+
});
535+
536+
await t.step("does not restart the server", () => {
537+
assertNotMatch(
538+
outputs.join(""),
539+
/Server stopped.*Restarting/,
540+
);
541+
});
542+
},
543+
);
492544
},
493545
});
494546

@@ -1275,3 +1327,8 @@ testHost({
12751327
});
12761328
},
12771329
});
1330+
1331+
/** Resolve testdata script URL. */
1332+
function resolve(path: string): string {
1333+
return new URL(`../../testdata/${path}`, import.meta.url).href;
1334+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import * as _ from "jsr:@std/async@1.0.0-constraint-error";

0 commit comments

Comments
 (0)