Skip to content

Commit

Permalink
👍 show constraint error warning (#404)
Browse files Browse the repository at this point in the history
* 👍 show constraint error warning

* 👍 simplify detecting the error message

* 🌿 clarify test issue
  • Loading branch information
Milly authored Aug 7, 2024
1 parent f5bcc4f commit df8b125
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
15 changes: 15 additions & 0 deletions autoload/denops/_internal/server/proc.vim
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,21 @@ function! s:on_exit(options, status) abort
let s:job = v:null
call denops#_internal#echo#debug(printf('Server stopped: %s', a:status))
call denops#_internal#event#emit(printf('DenopsSystemProcessStopped:%s', a:status))
const l:last_error = execute('20messages')
if l:last_error =~# 'Could not find constraint\|Could not find version of'
" Show a warning message when Deno module cache issue is detected
" https://github.com/vim-denops/denops.vim/issues/358
call denops#_internal#echo#warn(repeat('*', 80))
call denops#_internal#echo#warn('Deno module cache issue is detected.')
call denops#_internal#echo#warn(
\ "Execute 'call denops#cache#update(#{reload: v:true})' and restart Vim/Neovim."
\ )
call denops#_internal#echo#warn(
\ 'See https://github.com/vim-denops/denops.vim/issues/358 for more detail.'
\ )
call denops#_internal#echo#warn(repeat('*', 80))
return
endif
if s:job isnot# v:null || !a:options.restart_on_exit || s:stopped_on_purpose || s:exiting
return
endif
Expand Down
3 changes: 2 additions & 1 deletion deno.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"apply:supported-versions": "deno run --allow-read --allow-write .scripts/apply_supported_versions.ts"
},
"exclude": [
".coverage/"
".coverage/",
"tests/denops/testdata/no_check/"
],
// NOTE: Import maps should only be used from test modules.
"imports": {
Expand Down
57 changes: 57 additions & 0 deletions tests/denops/runtime/functions/server_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import {
assertEquals,
assertFalse,
assertMatch,
assertNotMatch,
assertRejects,
assertStringIncludes,
} from "jsr:@std/assert@^1.0.1";
import { delay } from "jsr:@std/async@^0.224.0/delay";
import { AsyncDisposableStack } from "jsr:@nick/dispose@^1.1.0/async-disposable-stack";
Expand Down Expand Up @@ -489,6 +491,56 @@ testHost({
);
});
});

await t.step(
"if the server is stopped with a constraint error (issue 401)",
async (t) => {
await using stack = new AsyncDisposableStack();
stack.defer(async () => {
await host.call("denops#server#stop");
await wait(
() => host.call("eval", "denops#server#status() ==# 'stopped'"),
);
});

outputs = [];
await host.call("execute", [
"silent! unlet g:__test_denops_process_stopped_fired",
`let g:denops#server#deno_args = ['${
resolve("no_check/cli_constraint_error_on_issue_401.ts")
}']`,
"let g:denops#server#restart_delay = 1000",
"let g:denops#server#restart_interval = 10000",
"let g:denops#server#restart_threshold = 1",
"call denops#server#start()",
], "");

await t.step("fires DenopsProcessStopped", async () => {
await wait(() =>
host.call("exists", "g:__test_denops_process_stopped_fired")
);
});

await t.step("changes status to 'stopped' asynchronously", async () => {
assertEquals(await host.call("denops#server#status"), "stopped");
});

await t.step("outputs warning message", async () => {
await delay(MESSAGE_DELAY);
assertStringIncludes(
outputs.join(""),
"Execute 'call denops#cache#update(#{reload: v:true})' and restart Vim/Neovim.",
);
});

await t.step("does not restart the server", () => {
assertNotMatch(
outputs.join(""),
/Server stopped.*Restarting/,
);
});
},
);
},
});

Expand Down Expand Up @@ -1275,3 +1327,8 @@ testHost({
});
},
});

/** Resolve testdata script URL. */
function resolve(path: string): string {
return new URL(`../../testdata/${path}`, import.meta.url).href;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import * as _ from "jsr:@std/async@1.0.0-constraint-error";

0 comments on commit df8b125

Please sign in to comment.