@codingame/monaco-languageclient-react 4.0.2 → 5.0.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 +20 -3
- package/dist/LanguageClient.js.map +1 -1
- package/package.json +11 -8
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,10 +1,20 @@
|
|
|
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);
|
|
@@ -14,6 +24,8 @@ function LanguageClient({ id, infrastructure, clientOptions, clientManagerOption
|
|
|
14
24
|
const isUserActive = useIsUserActive(userInactivityDelay);
|
|
15
25
|
const shouldShutdownLanguageClientForInactivity = useShouldShutdownLanguageClient(isUserActive, userInactivityShutdownDelay);
|
|
16
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) {
|
|
19
31
|
// eslint-disable-next-line no-console
|
|
@@ -23,8 +35,12 @@ function LanguageClient({ id, infrastructure, clientOptions, clientManagerOption
|
|
|
23
35
|
}
|
|
24
36
|
}, [willShutdown, restartAllowed]);
|
|
25
37
|
useEffect(() => {
|
|
38
|
+
languageClientCount++;
|
|
39
|
+
if (window.document.hasFocus()) {
|
|
40
|
+
writeStorage(ACTIVE_TAB_LOCAL_STORAGE_KEY, currentTab);
|
|
41
|
+
}
|
|
26
42
|
setWillShutdown(false);
|
|
27
|
-
if (shouldShutdownLanguageClientForInactivity) {
|
|
43
|
+
if (shouldShutdownLanguageClientForInactivity || shouldShutdownLanguageClientAsNotActiveTab) {
|
|
28
44
|
onDidChangeStatus({
|
|
29
45
|
status: 'inactivityShutdown'
|
|
30
46
|
});
|
|
@@ -42,6 +58,7 @@ function LanguageClient({ id, infrastructure, clientOptions, clientManagerOption
|
|
|
42
58
|
setWillShutdown(true);
|
|
43
59
|
});
|
|
44
60
|
return () => {
|
|
61
|
+
languageClientCount--;
|
|
45
62
|
errorDisposable.dispose();
|
|
46
63
|
statusChangeDisposable.dispose();
|
|
47
64
|
// eslint-disable-next-line no-console
|
|
@@ -54,7 +71,7 @@ function LanguageClient({ id, infrastructure, clientOptions, clientManagerOption
|
|
|
54
71
|
console.error('Unable to dispose language client', err);
|
|
55
72
|
});
|
|
56
73
|
};
|
|
57
|
-
}, [id, counter, shouldShutdownLanguageClientForInactivity, onError, onDidChangeStatus, onWillShutdown, infrastructure, clientOptions, clientManagerOptions]);
|
|
74
|
+
}, [id, counter, shouldShutdownLanguageClientForInactivity, onError, onDidChangeStatus, onWillShutdown, infrastructure, clientOptions, clientManagerOptions, shouldShutdownLanguageClientAsNotActiveTab]);
|
|
58
75
|
return null;
|
|
59
76
|
}
|
|
60
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
|
+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AAO,IAAI,CAAA;AACb,CAAC;AAED,eAAe,cAAc,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-languageclient-react",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "Monaco Editor React component",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"build": "npm run lint && npm run compile",
|
|
@@ -19,15 +19,17 @@
|
|
|
19
19
|
],
|
|
20
20
|
"types": "dist/index.d.ts",
|
|
21
21
|
"dependencies": {
|
|
22
|
-
"@codingame/monaco-languageclient-wrapper": "^
|
|
22
|
+
"@codingame/monaco-languageclient-wrapper": "^4.0.0",
|
|
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.
|
|
29
|
+
"@babel/core": "7.18.10",
|
|
28
30
|
"@babel/plugin-proposal-class-properties": "7.18.6",
|
|
29
31
|
"@babel/plugin-proposal-optional-chaining": "7.18.9",
|
|
30
|
-
"@babel/preset-env": "7.18.
|
|
32
|
+
"@babel/preset-env": "7.18.10",
|
|
31
33
|
"@babel/preset-react": "7.18.6",
|
|
32
34
|
"@babel/preset-typescript": "7.18.6",
|
|
33
35
|
"@babel/runtime": "7.18.9",
|
|
@@ -36,11 +38,12 @@
|
|
|
36
38
|
"@codingame/tsconfig": "^1.1.0",
|
|
37
39
|
"@types/deep-equal": "^1.0.1",
|
|
38
40
|
"@types/react": "17.0.40",
|
|
39
|
-
"@
|
|
40
|
-
"@typescript-eslint/
|
|
41
|
+
"@types/uuid": "^8.3.4",
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "5.33.1",
|
|
43
|
+
"@typescript-eslint/parser": "5.33.1",
|
|
41
44
|
"babel-eslint": "10.1.0",
|
|
42
45
|
"conventional-changelog-conventionalcommits": "^5.0.0",
|
|
43
|
-
"eslint": "8.
|
|
46
|
+
"eslint": "8.22.0",
|
|
44
47
|
"eslint-config-standard": "17.0.0",
|
|
45
48
|
"eslint-config-standard-jsx": "11.0.0",
|
|
46
49
|
"eslint-plugin-import": "2.26.0",
|