@codingame/monaco-vscode-language-detection-worker-service-override 4.0.0 → 4.1.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/languageDetectionWorker.js +2 -2
- package/package.json +2 -2
- package/external/tslib/tslib.es6.js +0 -11
- package/vscode/src/vs/workbench/contrib/languageDetection/browser/languageDetection.contribution.js +0 -157
- package/vscode/src/vs/workbench/services/languageDetection/browser/languageDetectionWorkerServiceImpl.js +0 -261
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SyncDescriptor } from 'vscode/vscode/vs/platform/instantiation/common/descriptors';
|
|
2
|
-
import { LanguageDetectionService } from '
|
|
2
|
+
import { LanguageDetectionService } from 'vscode/vscode/vs/workbench/services/languageDetection/browser/languageDetectionWorkerServiceImpl';
|
|
3
3
|
import { ILanguageDetectionService } from 'vscode/vscode/vs/workbench/services/languageDetection/common/languageDetectionWorkerService';
|
|
4
4
|
import { registerAssets } from 'vscode/assets';
|
|
5
|
-
import '
|
|
5
|
+
import 'vscode/vscode/vs/workbench/contrib/languageDetection/browser/languageDetection.contribution';
|
|
6
6
|
|
|
7
7
|
registerAssets({
|
|
8
8
|
'vs/../../node_modules/@vscode/vscode-languagedetection/model/model.json': new URL('@vscode/vscode-languagedetection/model/model.json', import.meta.url).href,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@codingame/monaco-vscode-language-detection-worker-service-override",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.1.0",
|
|
4
4
|
"keywords": [],
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "CodinGame",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"module": "index.js",
|
|
19
19
|
"types": "index.d.ts",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"vscode": "npm:@codingame/monaco-vscode-api@4.
|
|
21
|
+
"vscode": "npm:@codingame/monaco-vscode-api@4.1.0",
|
|
22
22
|
"@vscode/vscode-languagedetection": "1.0.21"
|
|
23
23
|
},
|
|
24
24
|
"exports": {
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
function __decorate(decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
}
|
|
7
|
-
function __param(paramIndex, decorator) {
|
|
8
|
-
return function (target, key) { decorator(target, key, paramIndex); }
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export { __decorate, __param };
|
package/vscode/src/vs/workbench/contrib/languageDetection/browser/languageDetection.contribution.js
DELETED
|
@@ -1,157 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { DisposableStore } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
3
|
-
import { getCodeEditor } from 'vscode/vscode/vs/editor/browser/editorBrowser';
|
|
4
|
-
import { localizeWithPath, localize2WithPath } from 'vscode/vscode/vs/nls';
|
|
5
|
-
import { Registry } from 'vscode/vscode/vs/platform/registry/common/platform';
|
|
6
|
-
import { Extensions } from 'vscode/vscode/vs/workbench/common/contributions';
|
|
7
|
-
import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
|
|
8
|
-
import { IStatusbarService } from 'vscode/vscode/vs/workbench/services/statusbar/browser/statusbar';
|
|
9
|
-
import { ILanguageDetectionService, LanguageDetectionLanguageEventSource } from 'vscode/vscode/vs/workbench/services/languageDetection/common/languageDetectionWorkerService';
|
|
10
|
-
import { ThrottledDelayer } from 'vscode/vscode/vs/base/common/async';
|
|
11
|
-
import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
|
|
12
|
-
import { IKeybindingService } from 'vscode/vscode/vs/platform/keybinding/common/keybinding';
|
|
13
|
-
import { registerAction2, Action2 } from 'vscode/vscode/vs/platform/actions/common/actions';
|
|
14
|
-
import { INotificationService } from 'vscode/vscode/vs/platform/notification/common/notification';
|
|
15
|
-
import { ContextKeyExpr } from 'vscode/vscode/vs/platform/contextkey/common/contextkey';
|
|
16
|
-
import { NOTEBOOK_EDITOR_EDITABLE } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookContextKeys';
|
|
17
|
-
import { EditorContextKeys } from 'vscode/vscode/vs/editor/common/editorContextKeys';
|
|
18
|
-
import { Schemas } from 'vscode/vscode/vs/base/common/network';
|
|
19
|
-
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
|
|
20
|
-
|
|
21
|
-
var LanguageDetectionStatusContribution_1;
|
|
22
|
-
const detectLanguageCommandId = 'editor.detectLanguage';
|
|
23
|
-
let LanguageDetectionStatusContribution = class LanguageDetectionStatusContribution {
|
|
24
|
-
static { LanguageDetectionStatusContribution_1 = this; }
|
|
25
|
-
static { this._id = 'status.languageDetectionStatus'; }
|
|
26
|
-
constructor(_languageDetectionService, _statusBarService, _configurationService, _editorService, _languageService, _keybindingService) {
|
|
27
|
-
this._languageDetectionService = _languageDetectionService;
|
|
28
|
-
this._statusBarService = _statusBarService;
|
|
29
|
-
this._configurationService = _configurationService;
|
|
30
|
-
this._editorService = _editorService;
|
|
31
|
-
this._languageService = _languageService;
|
|
32
|
-
this._keybindingService = _keybindingService;
|
|
33
|
-
this._disposables = ( new DisposableStore());
|
|
34
|
-
this._delayer = ( new ThrottledDelayer(1000));
|
|
35
|
-
this._renderDisposables = ( new DisposableStore());
|
|
36
|
-
_editorService.onDidActiveEditorChange(() => this._update(true), this, this._disposables);
|
|
37
|
-
this._update(false);
|
|
38
|
-
}
|
|
39
|
-
dispose() {
|
|
40
|
-
this._disposables.dispose();
|
|
41
|
-
this._delayer.dispose();
|
|
42
|
-
this._combinedEntry?.dispose();
|
|
43
|
-
this._renderDisposables.dispose();
|
|
44
|
-
}
|
|
45
|
-
_update(clear) {
|
|
46
|
-
if (clear) {
|
|
47
|
-
this._combinedEntry?.dispose();
|
|
48
|
-
this._combinedEntry = undefined;
|
|
49
|
-
}
|
|
50
|
-
this._delayer.trigger(() => this._doUpdate());
|
|
51
|
-
}
|
|
52
|
-
async _doUpdate() {
|
|
53
|
-
const editor = getCodeEditor(this._editorService.activeTextEditorControl);
|
|
54
|
-
this._renderDisposables.clear();
|
|
55
|
-
editor?.onDidChangeModelLanguage(() => this._update(true), this, this._renderDisposables);
|
|
56
|
-
editor?.onDidChangeModelContent(() => this._update(false), this, this._renderDisposables);
|
|
57
|
-
const editorModel = editor?.getModel();
|
|
58
|
-
const editorUri = editorModel?.uri;
|
|
59
|
-
const existingId = editorModel?.getLanguageId();
|
|
60
|
-
const enablementConfig = this._configurationService.getValue('workbench.editor.languageDetectionHints');
|
|
61
|
-
const enabled = typeof enablementConfig === 'object' && enablementConfig?.untitledEditors;
|
|
62
|
-
const disableLightbulb = !enabled || editorUri?.scheme !== Schemas.untitled || !existingId;
|
|
63
|
-
if (disableLightbulb || !editorUri) {
|
|
64
|
-
this._combinedEntry?.dispose();
|
|
65
|
-
this._combinedEntry = undefined;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
const lang = await this._languageDetectionService.detectLanguage(editorUri);
|
|
69
|
-
const skip = { 'jsonc': 'json' };
|
|
70
|
-
const existing = editorModel.getLanguageId();
|
|
71
|
-
if (lang && lang !== existing && skip[existing] !== lang) {
|
|
72
|
-
const detectedName = this._languageService.getLanguageName(lang) || lang;
|
|
73
|
-
let tooltip = ( localizeWithPath(
|
|
74
|
-
'vs/workbench/contrib/languageDetection/browser/languageDetection.contribution',
|
|
75
|
-
'status.autoDetectLanguage',
|
|
76
|
-
"Accept Detected Language: {0}",
|
|
77
|
-
detectedName
|
|
78
|
-
));
|
|
79
|
-
const keybinding = this._keybindingService.lookupKeybinding(detectLanguageCommandId);
|
|
80
|
-
const label = keybinding?.getLabel();
|
|
81
|
-
if (label) {
|
|
82
|
-
tooltip += ` (${label})`;
|
|
83
|
-
}
|
|
84
|
-
const props = {
|
|
85
|
-
name: ( localizeWithPath(
|
|
86
|
-
'vs/workbench/contrib/languageDetection/browser/languageDetection.contribution',
|
|
87
|
-
'langDetection.name',
|
|
88
|
-
"Language Detection"
|
|
89
|
-
)),
|
|
90
|
-
ariaLabel: ( localizeWithPath(
|
|
91
|
-
'vs/workbench/contrib/languageDetection/browser/languageDetection.contribution',
|
|
92
|
-
'langDetection.aria',
|
|
93
|
-
"Change to Detected Language: {0}",
|
|
94
|
-
lang
|
|
95
|
-
)),
|
|
96
|
-
tooltip,
|
|
97
|
-
command: detectLanguageCommandId,
|
|
98
|
-
text: '$(lightbulb-autofix)',
|
|
99
|
-
};
|
|
100
|
-
if (!this._combinedEntry) {
|
|
101
|
-
this._combinedEntry = this._statusBarService.addEntry(props, LanguageDetectionStatusContribution_1._id, 1 , { id: 'status.editor.mode', alignment: 1 , compact: true });
|
|
102
|
-
}
|
|
103
|
-
else {
|
|
104
|
-
this._combinedEntry.update(props);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
this._combinedEntry?.dispose();
|
|
109
|
-
this._combinedEntry = undefined;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
LanguageDetectionStatusContribution = LanguageDetectionStatusContribution_1 = ( __decorate([
|
|
115
|
-
( __param(0, ILanguageDetectionService)),
|
|
116
|
-
( __param(1, IStatusbarService)),
|
|
117
|
-
( __param(2, IConfigurationService)),
|
|
118
|
-
( __param(3, IEditorService)),
|
|
119
|
-
( __param(4, ILanguageService)),
|
|
120
|
-
( __param(5, IKeybindingService))
|
|
121
|
-
], LanguageDetectionStatusContribution));
|
|
122
|
-
( Registry.as(Extensions.Workbench)).registerWorkbenchContribution(LanguageDetectionStatusContribution, 3 );
|
|
123
|
-
registerAction2(class extends Action2 {
|
|
124
|
-
constructor() {
|
|
125
|
-
super({
|
|
126
|
-
id: detectLanguageCommandId,
|
|
127
|
-
title: ( localize2WithPath(
|
|
128
|
-
'vs/workbench/contrib/languageDetection/browser/languageDetection.contribution',
|
|
129
|
-
'detectlang',
|
|
130
|
-
"Detect Language from Content"
|
|
131
|
-
)),
|
|
132
|
-
f1: true,
|
|
133
|
-
precondition: ( ContextKeyExpr.and(( NOTEBOOK_EDITOR_EDITABLE.toNegated()), EditorContextKeys.editorTextFocus)),
|
|
134
|
-
keybinding: { primary: 34 | 512 | 1024 , weight: 200 }
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
async run(accessor) {
|
|
138
|
-
const editorService = accessor.get(IEditorService);
|
|
139
|
-
const languageDetectionService = accessor.get(ILanguageDetectionService);
|
|
140
|
-
const editor = getCodeEditor(editorService.activeTextEditorControl);
|
|
141
|
-
const notificationService = accessor.get(INotificationService);
|
|
142
|
-
const editorUri = editor?.getModel()?.uri;
|
|
143
|
-
if (editorUri) {
|
|
144
|
-
const lang = await languageDetectionService.detectLanguage(editorUri);
|
|
145
|
-
if (lang) {
|
|
146
|
-
editor.getModel()?.setLanguage(lang, LanguageDetectionLanguageEventSource);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
notificationService.warn(( localizeWithPath(
|
|
150
|
-
'vs/workbench/contrib/languageDetection/browser/languageDetection.contribution',
|
|
151
|
-
'noDetection',
|
|
152
|
-
"Unable to detect editor language"
|
|
153
|
-
)));
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
});
|
|
@@ -1,261 +0,0 @@
|
|
|
1
|
-
import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
|
|
2
|
-
import { Disposable } from 'vscode/vscode/vs/base/common/lifecycle';
|
|
3
|
-
import { LanguageDetectionStatsId } from 'vscode/vscode/vs/workbench/services/languageDetection/common/languageDetectionWorkerService';
|
|
4
|
-
import { FileAccess, Schemas, nodeModulesPath, nodeModulesAsarPath } from 'vscode/vscode/vs/base/common/network';
|
|
5
|
-
import { IWorkbenchEnvironmentService } from 'vscode/vscode/vs/workbench/services/environment/common/environmentService';
|
|
6
|
-
import { IConfigurationService } from 'vscode/vscode/vs/platform/configuration/common/configuration';
|
|
7
|
-
import { ILanguageService } from 'vscode/vscode/vs/editor/common/languages/language';
|
|
8
|
-
import { URI } from 'vscode/vscode/vs/base/common/uri';
|
|
9
|
-
import { isWeb } from 'vscode/vscode/vs/base/common/platform';
|
|
10
|
-
import { IModelService } from 'vscode/vscode/vs/editor/common/services/model';
|
|
11
|
-
import { SimpleWorkerClient } from 'vscode/vscode/vs/base/common/worker/simpleWorker';
|
|
12
|
-
import { ITelemetryService } from 'vscode/vscode/vs/platform/telemetry/common/telemetry';
|
|
13
|
-
import { EditorWorkerClient, EditorWorkerHost } from 'vscode/vscode/vs/editor/browser/services/editorWorkerService';
|
|
14
|
-
import { ILanguageConfigurationService } from 'vscode/vscode/vs/editor/common/languages/languageConfigurationRegistry';
|
|
15
|
-
import { IDiagnosticsService } from 'vscode/vscode/vs/platform/diagnostics/common/diagnostics';
|
|
16
|
-
import { IWorkspaceContextService } from 'vscode/vscode/vs/platform/workspace/common/workspace';
|
|
17
|
-
import { IEditorService } from 'vscode/vscode/vs/workbench/services/editor/common/editorService';
|
|
18
|
-
import { IStorageService } from 'vscode/vscode/vs/platform/storage/common/storage';
|
|
19
|
-
import { LRUCache } from 'vscode/vscode/vs/base/common/map';
|
|
20
|
-
import { ILogService } from 'vscode/vscode/vs/platform/log/common/log';
|
|
21
|
-
|
|
22
|
-
var LanguageDetectionService_1;
|
|
23
|
-
const TOP_LANG_COUNTS = 12;
|
|
24
|
-
const regexpModuleLocation = `${nodeModulesPath}/vscode-regexp-languagedetection`;
|
|
25
|
-
const regexpModuleLocationAsar = `${nodeModulesAsarPath}/vscode-regexp-languagedetection`;
|
|
26
|
-
const moduleLocation = `${nodeModulesPath}/@vscode/vscode-languagedetection`;
|
|
27
|
-
const moduleLocationAsar = `${nodeModulesAsarPath}/@vscode/vscode-languagedetection`;
|
|
28
|
-
let LanguageDetectionService = class LanguageDetectionService extends Disposable {
|
|
29
|
-
static { LanguageDetectionService_1 = this; }
|
|
30
|
-
static { this.enablementSettingKey = 'workbench.editor.languageDetection'; }
|
|
31
|
-
static { this.historyBasedEnablementConfig = 'workbench.editor.historyBasedLanguageDetection'; }
|
|
32
|
-
static { this.preferHistoryConfig = 'workbench.editor.preferHistoryBasedLanguageDetection'; }
|
|
33
|
-
static { this.workspaceOpenedLanguagesStorageKey = 'workbench.editor.languageDetectionOpenedLanguages.workspace'; }
|
|
34
|
-
static { this.globalOpenedLanguagesStorageKey = 'workbench.editor.languageDetectionOpenedLanguages.global'; }
|
|
35
|
-
constructor(_environmentService, languageService, _configurationService, _diagnosticsService, _workspaceContextService, modelService, _editorService, telemetryService, storageService, _logService, languageConfigurationService) {
|
|
36
|
-
super();
|
|
37
|
-
this._environmentService = _environmentService;
|
|
38
|
-
this._configurationService = _configurationService;
|
|
39
|
-
this._diagnosticsService = _diagnosticsService;
|
|
40
|
-
this._workspaceContextService = _workspaceContextService;
|
|
41
|
-
this._editorService = _editorService;
|
|
42
|
-
this._logService = _logService;
|
|
43
|
-
this.hasResolvedWorkspaceLanguageIds = false;
|
|
44
|
-
this.workspaceLanguageIds = ( new Set());
|
|
45
|
-
this.sessionOpenedLanguageIds = ( new Set());
|
|
46
|
-
this.historicalGlobalOpenedLanguageIds = ( new LRUCache(TOP_LANG_COUNTS));
|
|
47
|
-
this.historicalWorkspaceOpenedLanguageIds = ( new LRUCache(TOP_LANG_COUNTS));
|
|
48
|
-
this.dirtyBiases = true;
|
|
49
|
-
this.langBiases = {};
|
|
50
|
-
this._languageDetectionWorkerClient = this._register(( new LanguageDetectionWorkerClient(
|
|
51
|
-
modelService,
|
|
52
|
-
languageService,
|
|
53
|
-
telemetryService,
|
|
54
|
-
this._environmentService.isBuilt && !isWeb
|
|
55
|
-
? ( ( FileAccess.asBrowserUri(`${moduleLocationAsar}/dist/lib/index.js`)).toString(true))
|
|
56
|
-
: ( ( FileAccess.asBrowserUri(`${moduleLocation}/dist/lib/index.js`)).toString(true)),
|
|
57
|
-
this._environmentService.isBuilt && !isWeb
|
|
58
|
-
? ( ( FileAccess.asBrowserUri(`${moduleLocationAsar}/model/model.json`)).toString(true))
|
|
59
|
-
: ( ( FileAccess.asBrowserUri(`${moduleLocation}/model/model.json`)).toString(true)),
|
|
60
|
-
this._environmentService.isBuilt && !isWeb
|
|
61
|
-
? ( ( FileAccess.asBrowserUri(`${moduleLocationAsar}/model/group1-shard1of1.bin`)).toString(true))
|
|
62
|
-
: ( ( FileAccess.asBrowserUri(`${moduleLocation}/model/group1-shard1of1.bin`)).toString(true)),
|
|
63
|
-
this._environmentService.isBuilt && !isWeb
|
|
64
|
-
? ( ( FileAccess.asBrowserUri(`${regexpModuleLocationAsar}/dist/index.js`)).toString(true))
|
|
65
|
-
: ( ( FileAccess.asBrowserUri(`${regexpModuleLocation}/dist/index.js`)).toString(true)),
|
|
66
|
-
languageConfigurationService
|
|
67
|
-
)));
|
|
68
|
-
this.initEditorOpenedListeners(storageService);
|
|
69
|
-
}
|
|
70
|
-
async resolveWorkspaceLanguageIds() {
|
|
71
|
-
if (this.hasResolvedWorkspaceLanguageIds) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
this.hasResolvedWorkspaceLanguageIds = true;
|
|
75
|
-
const fileExtensions = await this._diagnosticsService.getWorkspaceFileExtensions(this._workspaceContextService.getWorkspace());
|
|
76
|
-
let count = 0;
|
|
77
|
-
for (const ext of fileExtensions.extensions) {
|
|
78
|
-
const langId = this._languageDetectionWorkerClient.getLanguageId(ext);
|
|
79
|
-
if (langId && count < TOP_LANG_COUNTS) {
|
|
80
|
-
this.workspaceLanguageIds.add(langId);
|
|
81
|
-
count++;
|
|
82
|
-
if (count > TOP_LANG_COUNTS) {
|
|
83
|
-
break;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
this.dirtyBiases = true;
|
|
88
|
-
}
|
|
89
|
-
isEnabledForLanguage(languageId) {
|
|
90
|
-
return !!languageId && this._configurationService.getValue(LanguageDetectionService_1.enablementSettingKey, { overrideIdentifier: languageId });
|
|
91
|
-
}
|
|
92
|
-
getLanguageBiases() {
|
|
93
|
-
if (!this.dirtyBiases) {
|
|
94
|
-
return this.langBiases;
|
|
95
|
-
}
|
|
96
|
-
const biases = {};
|
|
97
|
-
this.sessionOpenedLanguageIds.forEach(lang => biases[lang] = (biases[lang] ?? 0) + 7);
|
|
98
|
-
this.workspaceLanguageIds.forEach(lang => biases[lang] = (biases[lang] ?? 0) + 5);
|
|
99
|
-
[...( this.historicalWorkspaceOpenedLanguageIds.keys())].forEach(lang => biases[lang] = (biases[lang] ?? 0) + 3);
|
|
100
|
-
[...( this.historicalGlobalOpenedLanguageIds.keys())].forEach(lang => biases[lang] = (biases[lang] ?? 0) + 1);
|
|
101
|
-
this._logService.trace('Session Languages:', JSON.stringify([...this.sessionOpenedLanguageIds]));
|
|
102
|
-
this._logService.trace('Workspace Languages:', JSON.stringify([...this.workspaceLanguageIds]));
|
|
103
|
-
this._logService.trace('Historical Workspace Opened Languages:', JSON.stringify([...( this.historicalWorkspaceOpenedLanguageIds.keys())]));
|
|
104
|
-
this._logService.trace('Historical Globally Opened Languages:', JSON.stringify([...( this.historicalGlobalOpenedLanguageIds.keys())]));
|
|
105
|
-
this._logService.trace('Computed Language Detection Biases:', JSON.stringify(biases));
|
|
106
|
-
this.dirtyBiases = false;
|
|
107
|
-
this.langBiases = biases;
|
|
108
|
-
return biases;
|
|
109
|
-
}
|
|
110
|
-
async detectLanguage(resource, supportedLangs) {
|
|
111
|
-
const useHistory = this._configurationService.getValue(LanguageDetectionService_1.historyBasedEnablementConfig);
|
|
112
|
-
const preferHistory = this._configurationService.getValue(LanguageDetectionService_1.preferHistoryConfig);
|
|
113
|
-
if (useHistory) {
|
|
114
|
-
await this.resolveWorkspaceLanguageIds();
|
|
115
|
-
}
|
|
116
|
-
const biases = useHistory ? this.getLanguageBiases() : undefined;
|
|
117
|
-
return this._languageDetectionWorkerClient.detectLanguage(resource, biases, preferHistory, supportedLangs);
|
|
118
|
-
}
|
|
119
|
-
initEditorOpenedListeners(storageService) {
|
|
120
|
-
try {
|
|
121
|
-
const globalLangHistoryData = JSON.parse(storageService.get(LanguageDetectionService_1.globalOpenedLanguagesStorageKey, 0 , '[]'));
|
|
122
|
-
this.historicalGlobalOpenedLanguageIds.fromJSON(globalLangHistoryData);
|
|
123
|
-
}
|
|
124
|
-
catch (e) {
|
|
125
|
-
console.error(e);
|
|
126
|
-
}
|
|
127
|
-
try {
|
|
128
|
-
const workspaceLangHistoryData = JSON.parse(storageService.get(LanguageDetectionService_1.workspaceOpenedLanguagesStorageKey, 1 , '[]'));
|
|
129
|
-
this.historicalWorkspaceOpenedLanguageIds.fromJSON(workspaceLangHistoryData);
|
|
130
|
-
}
|
|
131
|
-
catch (e) {
|
|
132
|
-
console.error(e);
|
|
133
|
-
}
|
|
134
|
-
this._register(this._editorService.onDidActiveEditorChange(() => {
|
|
135
|
-
const activeLanguage = this._editorService.activeTextEditorLanguageId;
|
|
136
|
-
if (activeLanguage && this._editorService.activeEditor?.resource?.scheme !== Schemas.untitled) {
|
|
137
|
-
this.sessionOpenedLanguageIds.add(activeLanguage);
|
|
138
|
-
this.historicalGlobalOpenedLanguageIds.set(activeLanguage, true);
|
|
139
|
-
this.historicalWorkspaceOpenedLanguageIds.set(activeLanguage, true);
|
|
140
|
-
storageService.store(LanguageDetectionService_1.globalOpenedLanguagesStorageKey, JSON.stringify(this.historicalGlobalOpenedLanguageIds.toJSON()), 0 , 1 );
|
|
141
|
-
storageService.store(LanguageDetectionService_1.workspaceOpenedLanguagesStorageKey, JSON.stringify(this.historicalWorkspaceOpenedLanguageIds.toJSON()), 1 , 1 );
|
|
142
|
-
this.dirtyBiases = true;
|
|
143
|
-
}
|
|
144
|
-
}));
|
|
145
|
-
}
|
|
146
|
-
};
|
|
147
|
-
LanguageDetectionService = LanguageDetectionService_1 = ( __decorate([
|
|
148
|
-
( __param(0, IWorkbenchEnvironmentService)),
|
|
149
|
-
( __param(1, ILanguageService)),
|
|
150
|
-
( __param(2, IConfigurationService)),
|
|
151
|
-
( __param(3, IDiagnosticsService)),
|
|
152
|
-
( __param(4, IWorkspaceContextService)),
|
|
153
|
-
( __param(5, IModelService)),
|
|
154
|
-
( __param(6, IEditorService)),
|
|
155
|
-
( __param(7, ITelemetryService)),
|
|
156
|
-
( __param(8, IStorageService)),
|
|
157
|
-
( __param(9, ILogService)),
|
|
158
|
-
( __param(10, ILanguageConfigurationService))
|
|
159
|
-
], LanguageDetectionService));
|
|
160
|
-
class LanguageDetectionWorkerClient extends EditorWorkerClient {
|
|
161
|
-
constructor(modelService, _languageService, _telemetryService, _indexJsUri, _modelJsonUri, _weightsUri, _regexpModelUri, languageConfigurationService) {
|
|
162
|
-
super(modelService, true, 'languageDetectionWorkerService', languageConfigurationService);
|
|
163
|
-
this._languageService = _languageService;
|
|
164
|
-
this._telemetryService = _telemetryService;
|
|
165
|
-
this._indexJsUri = _indexJsUri;
|
|
166
|
-
this._modelJsonUri = _modelJsonUri;
|
|
167
|
-
this._weightsUri = _weightsUri;
|
|
168
|
-
this._regexpModelUri = _regexpModelUri;
|
|
169
|
-
}
|
|
170
|
-
_getOrCreateLanguageDetectionWorker() {
|
|
171
|
-
if (this.workerPromise) {
|
|
172
|
-
return this.workerPromise;
|
|
173
|
-
}
|
|
174
|
-
this.workerPromise = ( new Promise((resolve, reject) => {
|
|
175
|
-
resolve(this._register(( new SimpleWorkerClient(
|
|
176
|
-
this._workerFactory,
|
|
177
|
-
'vs/workbench/services/languageDetection/browser/languageDetectionSimpleWorker',
|
|
178
|
-
( new EditorWorkerHost(this))
|
|
179
|
-
))));
|
|
180
|
-
}));
|
|
181
|
-
return this.workerPromise;
|
|
182
|
-
}
|
|
183
|
-
_guessLanguageIdByUri(uri) {
|
|
184
|
-
const guess = this._languageService.guessLanguageIdByFilepathOrFirstLine(uri);
|
|
185
|
-
if (guess && guess !== 'unknown') {
|
|
186
|
-
return guess;
|
|
187
|
-
}
|
|
188
|
-
return undefined;
|
|
189
|
-
}
|
|
190
|
-
async _getProxy() {
|
|
191
|
-
return (await this._getOrCreateLanguageDetectionWorker()).getProxyObject();
|
|
192
|
-
}
|
|
193
|
-
async fhr(method, args) {
|
|
194
|
-
switch (method) {
|
|
195
|
-
case 'getIndexJsUri':
|
|
196
|
-
return this.getIndexJsUri();
|
|
197
|
-
case 'getModelJsonUri':
|
|
198
|
-
return this.getModelJsonUri();
|
|
199
|
-
case 'getWeightsUri':
|
|
200
|
-
return this.getWeightsUri();
|
|
201
|
-
case 'getRegexpModelUri':
|
|
202
|
-
return this.getRegexpModelUri();
|
|
203
|
-
case 'getLanguageId':
|
|
204
|
-
return this.getLanguageId(args[0]);
|
|
205
|
-
case 'sendTelemetryEvent':
|
|
206
|
-
return this.sendTelemetryEvent(args[0], args[1], args[2]);
|
|
207
|
-
default:
|
|
208
|
-
return super.fhr(method, args);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
async getIndexJsUri() {
|
|
212
|
-
return this._indexJsUri;
|
|
213
|
-
}
|
|
214
|
-
getLanguageId(languageIdOrExt) {
|
|
215
|
-
if (!languageIdOrExt) {
|
|
216
|
-
return undefined;
|
|
217
|
-
}
|
|
218
|
-
if (this._languageService.isRegisteredLanguageId(languageIdOrExt)) {
|
|
219
|
-
return languageIdOrExt;
|
|
220
|
-
}
|
|
221
|
-
const guessed = this._guessLanguageIdByUri(URI.file(`file.${languageIdOrExt}`));
|
|
222
|
-
if (!guessed || guessed === 'unknown') {
|
|
223
|
-
return undefined;
|
|
224
|
-
}
|
|
225
|
-
return guessed;
|
|
226
|
-
}
|
|
227
|
-
async getModelJsonUri() {
|
|
228
|
-
return this._modelJsonUri;
|
|
229
|
-
}
|
|
230
|
-
async getWeightsUri() {
|
|
231
|
-
return this._weightsUri;
|
|
232
|
-
}
|
|
233
|
-
async getRegexpModelUri() {
|
|
234
|
-
return this._regexpModelUri;
|
|
235
|
-
}
|
|
236
|
-
async sendTelemetryEvent(languages, confidences, timeSpent) {
|
|
237
|
-
this._telemetryService.publicLog2(LanguageDetectionStatsId, {
|
|
238
|
-
languages: languages.join(','),
|
|
239
|
-
confidences: confidences.join(','),
|
|
240
|
-
timeSpent
|
|
241
|
-
});
|
|
242
|
-
}
|
|
243
|
-
async detectLanguage(resource, langBiases, preferHistory, supportedLangs) {
|
|
244
|
-
const startTime = Date.now();
|
|
245
|
-
const quickGuess = this._guessLanguageIdByUri(resource);
|
|
246
|
-
if (quickGuess) {
|
|
247
|
-
return quickGuess;
|
|
248
|
-
}
|
|
249
|
-
await this._withSyncedResources([resource]);
|
|
250
|
-
const modelId = await (await this._getProxy()).detectLanguage(( resource.toString()), langBiases, preferHistory, supportedLangs);
|
|
251
|
-
const languageId = this.getLanguageId(modelId);
|
|
252
|
-
const LanguageDetectionStatsId = 'automaticlanguagedetection.perf';
|
|
253
|
-
this._telemetryService.publicLog2(LanguageDetectionStatsId, {
|
|
254
|
-
timeSpent: Date.now() - startTime,
|
|
255
|
-
detection: languageId || 'unknown',
|
|
256
|
-
});
|
|
257
|
-
return languageId;
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
export { LanguageDetectionService, LanguageDetectionWorkerClient };
|