@codingame/monaco-languageclient-react 4.0.1 → 4.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/LanguageClient.d.ts +3 -1
- package/dist/LanguageClient.js +27 -6
- package/dist/LanguageClient.js.map +1 -1
- package/package.json +24 -20
package/dist/LanguageClient.d.ts
CHANGED
|
@@ -16,6 +16,8 @@ export interface LanguageClientProps {
|
|
|
16
16
|
userInactivityDelay?: number;
|
|
17
17
|
/** Shutdown the language client when the user stay inactive during this duration (default 60 seconds) */
|
|
18
18
|
userInactivityShutdownDelay?: number;
|
|
19
|
+
/** Allow only a single tab to have active language clients (the most recently focused one) */
|
|
20
|
+
singleActiveTab?: boolean;
|
|
19
21
|
}
|
|
20
|
-
declare function LanguageClient({ id, infrastructure, clientOptions, clientManagerOptions, onError: _onError, onDidChangeStatus: _onDidChangeStatus, onWillShutdown: _onWillShutdown, userInactivityDelay, userInactivityShutdownDelay }: LanguageClientProps): ReactElement | null;
|
|
22
|
+
declare function LanguageClient({ id, infrastructure, clientOptions, clientManagerOptions, onError: _onError, onDidChangeStatus: _onDidChangeStatus, onWillShutdown: _onWillShutdown, userInactivityDelay, userInactivityShutdownDelay, singleActiveTab }: LanguageClientProps): ReactElement | null;
|
|
21
23
|
export default LanguageClient;
|
package/dist/LanguageClient.js
CHANGED
|
@@ -1,34 +1,52 @@
|
|
|
1
1
|
import { useEffect, useRef, useState } from 'react';
|
|
2
2
|
import { createLanguageClientManager } from '@codingame/monaco-languageclient-wrapper';
|
|
3
|
+
import { useLocalStorage, writeStorage } from '@rehooks/local-storage';
|
|
4
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
3
5
|
import useIsUserActive from './hooks/useIsUserActive';
|
|
4
6
|
import useShouldShutdownLanguageClient from './hooks/useShouldShutdownLanguageClient';
|
|
5
7
|
import { useLastVersion } from './hooks/useLastVersion';
|
|
6
8
|
const noop = () => null;
|
|
7
|
-
|
|
9
|
+
const ACTIVE_TAB_LOCAL_STORAGE_KEY = 'monaco-lsp-active-tab';
|
|
10
|
+
const currentTab = uuidv4();
|
|
11
|
+
let languageClientCount = 0;
|
|
12
|
+
window.addEventListener('focus', () => {
|
|
13
|
+
if (languageClientCount > 0) {
|
|
14
|
+
writeStorage(ACTIVE_TAB_LOCAL_STORAGE_KEY, currentTab);
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
function LanguageClient({ id, infrastructure, clientOptions, clientManagerOptions, onError: _onError, onDidChangeStatus: _onDidChangeStatus, onWillShutdown: _onWillShutdown, userInactivityDelay = 30 * 1000, userInactivityShutdownDelay = 60 * 1000, singleActiveTab = true }) {
|
|
8
18
|
const onError = useLastVersion(_onError ?? noop);
|
|
9
19
|
const onDidChangeStatus = useLastVersion(_onDidChangeStatus ?? noop);
|
|
10
20
|
const onWillShutdown = useLastVersion(_onWillShutdown ?? noop);
|
|
11
21
|
const languageClientRef = useRef();
|
|
12
22
|
const [willShutdown, setWillShutdown] = useState(false);
|
|
13
23
|
const [counter, setCounter] = useState(1);
|
|
14
|
-
const
|
|
15
|
-
const shouldShutdownLanguageClientForInactivity = useShouldShutdownLanguageClient(
|
|
16
|
-
const restartAllowed = !
|
|
24
|
+
const isUserActive = useIsUserActive(userInactivityDelay);
|
|
25
|
+
const shouldShutdownLanguageClientForInactivity = useShouldShutdownLanguageClient(isUserActive, userInactivityShutdownDelay);
|
|
26
|
+
const restartAllowed = !isUserActive;
|
|
27
|
+
const [activeTab] = useLocalStorage(ACTIVE_TAB_LOCAL_STORAGE_KEY);
|
|
28
|
+
const shouldShutdownLanguageClientAsNotActiveTab = singleActiveTab && activeTab !== currentTab;
|
|
17
29
|
useEffect(() => {
|
|
18
30
|
if (willShutdown && restartAllowed) {
|
|
31
|
+
// eslint-disable-next-line no-console
|
|
19
32
|
console.info('Restarting language client because the current instance will be shutdown');
|
|
20
33
|
setCounter(v => v + 1);
|
|
21
34
|
setWillShutdown(false);
|
|
22
35
|
}
|
|
23
36
|
}, [willShutdown, restartAllowed]);
|
|
24
37
|
useEffect(() => {
|
|
38
|
+
languageClientCount++;
|
|
39
|
+
if (window.document.hasFocus()) {
|
|
40
|
+
writeStorage(ACTIVE_TAB_LOCAL_STORAGE_KEY, currentTab);
|
|
41
|
+
}
|
|
25
42
|
setWillShutdown(false);
|
|
26
|
-
if (shouldShutdownLanguageClientForInactivity) {
|
|
43
|
+
if (shouldShutdownLanguageClientForInactivity || shouldShutdownLanguageClientAsNotActiveTab) {
|
|
27
44
|
onDidChangeStatus({
|
|
28
45
|
status: 'inactivityShutdown'
|
|
29
46
|
});
|
|
30
47
|
return;
|
|
31
48
|
}
|
|
49
|
+
// eslint-disable-next-line no-console
|
|
32
50
|
console.info(`Starting language server for language ${id}`);
|
|
33
51
|
const languageClient = createLanguageClientManager(id, infrastructure, clientOptions, clientManagerOptions);
|
|
34
52
|
languageClientRef.current = languageClient;
|
|
@@ -40,17 +58,20 @@ function LanguageClient({ id, infrastructure, clientOptions, clientManagerOption
|
|
|
40
58
|
setWillShutdown(true);
|
|
41
59
|
});
|
|
42
60
|
return () => {
|
|
61
|
+
languageClientCount--;
|
|
43
62
|
errorDisposable.dispose();
|
|
44
63
|
statusChangeDisposable.dispose();
|
|
64
|
+
// eslint-disable-next-line no-console
|
|
45
65
|
console.info('Shutting down language server');
|
|
46
66
|
clearTimeout(startTimeout);
|
|
47
67
|
languageClient.dispose().then(() => {
|
|
68
|
+
// eslint-disable-next-line no-console
|
|
48
69
|
console.info('Language server shut down');
|
|
49
70
|
}, err => {
|
|
50
71
|
console.error('Unable to dispose language client', err);
|
|
51
72
|
});
|
|
52
73
|
};
|
|
53
|
-
}, [id, counter, shouldShutdownLanguageClientForInactivity, onError, onDidChangeStatus, onWillShutdown, infrastructure, clientOptions, clientManagerOptions]);
|
|
74
|
+
}, [id, counter, shouldShutdownLanguageClientForInactivity, onError, onDidChangeStatus, onWillShutdown, infrastructure, clientOptions, clientManagerOptions, shouldShutdownLanguageClientAsNotActiveTab]);
|
|
54
75
|
return null;
|
|
55
76
|
}
|
|
56
77
|
export default LanguageClient;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LanguageClient.js","sourceRoot":"","sources":["../src/LanguageClient.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACjE,OAAO,EAAE,2BAA2B,EAAmL,MAAM,0CAA0C,CAAA;AACvQ,OAAO,eAAe,MAAM,yBAAyB,CAAA;AACrD,OAAO,+BAA+B,MAAM,yCAAyC,CAAA;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;
|
|
1
|
+
{"version":3,"file":"LanguageClient.js","sourceRoot":"","sources":["../src/LanguageClient.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgB,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AACjE,OAAO,EAAE,2BAA2B,EAAmL,MAAM,0CAA0C,CAAA;AACvQ,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAA;AACtE,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,eAAe,MAAM,yBAAyB,CAAA;AACrD,OAAO,+BAA+B,MAAM,yCAAyC,CAAA;AACrF,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAA;AAuBvD,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,IAAI,CAAA;AAEvB,MAAM,4BAA4B,GAAG,uBAAuB,CAAA;AAC5D,MAAM,UAAU,GAAG,MAAM,EAAE,CAAA;AAC3B,IAAI,mBAAmB,GAAG,CAAC,CAAA;AAE3B,MAAM,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;IACpC,IAAI,mBAAmB,GAAG,CAAC,EAAE;QAC3B,YAAY,CAAC,4BAA4B,EAAE,UAAU,CAAC,CAAA;KACvD;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AC1B,cAAc,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE;gBACjC,sCAAsC;gBACtC,OAAO,CAAC,IAAI,CAAC,2BAA2B,CAAC,CAAA;YAC3C,CAAC,EAAE,GAAG,CAAC,EAAE;gBACP,OAAO,CAAC,KAAK,CAAC,mCAAmC,EAAE,GAAG,CAAC,CAAA;YACzD,CAAC,CAAC,CAAA;QACJ,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,yCAAyC,EAAE,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EAAE,aAAa,EAAE,oBAAoB,EAAE,0CAA0C,CAAC,CAAC,CAAA;IAEzM,OAAO,IAAI,CAAA;AACb,CAAC;AAED,eAAe,cAAc,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-languageclient-react",
|
|
3
|
-
"version": "4.0
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Monaco Editor React component",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm run lint && npm run compile",
|
|
7
7
|
"compile": "tsc",
|
|
8
|
-
"lint": "eslint --ext .ts src"
|
|
8
|
+
"lint": "eslint --ext .ts --ext .tsx src"
|
|
9
9
|
},
|
|
10
10
|
"repository": {
|
|
11
11
|
"type": "git",
|
|
@@ -19,36 +19,40 @@
|
|
|
19
19
|
],
|
|
20
20
|
"types": "dist/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@codingame/monaco-languageclient-wrapper": "^3.
|
|
22
|
+
"@codingame/monaco-languageclient-wrapper": "^3.2.5",
|
|
23
|
+
"@rehooks/local-storage": "^2.4.4",
|
|
23
24
|
"activity-detector": "^3.0.0",
|
|
24
|
-
"react": ">=16.0.0"
|
|
25
|
+
"react": ">=16.0.0",
|
|
26
|
+
"uuid": "^8.3.2"
|
|
25
27
|
},
|
|
26
28
|
"devDependencies": {
|
|
27
|
-
"@babel/core": "7.18.
|
|
28
|
-
"@babel/plugin-proposal-class-properties": "7.
|
|
29
|
-
"@babel/plugin-proposal-optional-chaining": "7.
|
|
30
|
-
"@babel/preset-env": "7.18.
|
|
31
|
-
"@babel/preset-react": "7.
|
|
32
|
-
"@babel/preset-typescript": "7.
|
|
33
|
-
"@babel/runtime": "7.18.
|
|
34
|
-
"@codingame/eslint-config": "^1.1.
|
|
35
|
-
"@codingame/
|
|
29
|
+
"@babel/core": "7.18.9",
|
|
30
|
+
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
31
|
+
"@babel/plugin-proposal-optional-chaining": "7.18.9",
|
|
32
|
+
"@babel/preset-env": "7.18.9",
|
|
33
|
+
"@babel/preset-react": "7.18.6",
|
|
34
|
+
"@babel/preset-typescript": "7.18.6",
|
|
35
|
+
"@babel/runtime": "7.18.9",
|
|
36
|
+
"@codingame/eslint-config": "^1.1.6",
|
|
37
|
+
"@codingame/eslint-config-react": "^1.0.1",
|
|
38
|
+
"@codingame/tsconfig": "^1.1.0",
|
|
36
39
|
"@types/deep-equal": "^1.0.1",
|
|
37
|
-
"@types/react": "
|
|
38
|
-
"@
|
|
39
|
-
"@typescript-eslint/
|
|
40
|
+
"@types/react": "17.0.40",
|
|
41
|
+
"@types/uuid": "^8.3.4",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "5.30.7",
|
|
43
|
+
"@typescript-eslint/parser": "5.30.7",
|
|
40
44
|
"babel-eslint": "10.1.0",
|
|
41
45
|
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
42
|
-
"eslint": "8.
|
|
46
|
+
"eslint": "8.20.0",
|
|
43
47
|
"eslint-config-standard": "17.0.0",
|
|
44
48
|
"eslint-config-standard-jsx": "11.0.0",
|
|
45
49
|
"eslint-plugin-import": "2.26.0",
|
|
46
50
|
"eslint-plugin-node": "11.1.0",
|
|
47
51
|
"eslint-plugin-promise": "6.0.0",
|
|
48
|
-
"eslint-plugin-react": "7.30.
|
|
49
|
-
"eslint-plugin-react-hooks": "
|
|
52
|
+
"eslint-plugin-react": "7.30.1",
|
|
53
|
+
"eslint-plugin-react-hooks": "4.6.0",
|
|
50
54
|
"eslint-plugin-unused-imports": "2.0.0",
|
|
51
|
-
"typescript": "4.7.
|
|
55
|
+
"typescript": "4.7.4"
|
|
52
56
|
},
|
|
53
57
|
"browserslist": [
|
|
54
58
|
"defaults",
|