diff --git a/extensions/html-language-features/server/src/htmlServerMain.ts b/extensions/html-language-features/server/src/htmlServerMain.ts
index 2ccb26c3f60f0..bcc3feedf122a 100644
--- a/extensions/html-language-features/server/src/htmlServerMain.ts
+++ b/extensions/html-language-features/server/src/htmlServerMain.ts
@@ -480,17 +480,19 @@ connection.onFoldingRanges((params, token) => {
}, null, `Error while computing folding regions for ${params.textDocument.uri}`, token);
});
-connection.onRequest('$/textDocument/selectionRange', async (params) => {
- const document = documents.get(params.textDocument.uri);
- const position: Position = params.position;
-
- if (document) {
- const htmlMode = languageModes.getMode('html');
- if (htmlMode && htmlMode.doSelection) {
- return htmlMode.doSelection(document, position);
+connection.onRequest('$/textDocument/selectionRange', async (params, token) => {
+ return runSafe(() => {
+ const document = documents.get(params.textDocument.uri);
+ const position: Position = params.position;
+
+ if (document) {
+ const htmlMode = languageModes.getMode('html');
+ if (htmlMode && htmlMode.doSelection) {
+ return htmlMode.doSelection(document, position);
+ }
}
- }
- return Promise.resolve(null);
+ return Promise.resolve(null);
+ }, null, `Error while computing selection ranges for ${params.textDocument.uri}`, token);
});