@codingame/monaco-vscode-language-detection-worker-service-override 1.85.0 → 1.85.2

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.
@@ -2,6 +2,7 @@ import { SyncDescriptor } from 'monaco-editor/esm/vs/platform/instantiation/comm
2
2
  import { LanguageDetectionService } from './vscode/src/vs/workbench/services/languageDetection/browser/languageDetectionWorkerServiceImpl.js';
3
3
  import { ILanguageDetectionService } from 'vscode/vscode/vs/workbench/services/languageDetection/common/languageDetectionWorkerService';
4
4
  import { registerAssets } from 'vscode/assets';
5
+ import './vscode/src/vs/workbench/contrib/languageDetection/browser/languageDetection.contribution.js';
5
6
 
6
7
  registerAssets({
7
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": "1.85.0",
3
+ "version": "1.85.2",
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@1.85.0",
21
+ "vscode": "npm:@codingame/monaco-vscode-api@1.85.2",
22
22
  "@vscode/vscode-languagedetection": "1.0.21",
23
23
  "monaco-editor": "0.45.0"
24
24
  },
@@ -0,0 +1,157 @@
1
+ import { __decorate, __param } from '../../../../../../../external/tslib/tslib.es6.js';
2
+ import { DisposableStore } from 'monaco-editor/esm/vs/base/common/lifecycle.js';
3
+ import { getCodeEditor } from 'monaco-editor/esm/vs/editor/browser/editorBrowser.js';
4
+ import { localizeWithPath } from 'monaco-editor/esm/vs/nls.js';
5
+ import { Registry } from 'monaco-editor/esm/vs/platform/registry/common/platform.js';
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 'monaco-editor/esm/vs/base/common/async.js';
11
+ import { ILanguageService } from 'monaco-editor/esm/vs/editor/common/languages/language.js';
12
+ import { IKeybindingService } from 'monaco-editor/esm/vs/platform/keybinding/common/keybinding.js';
13
+ import { registerAction2, Action2 } from 'monaco-editor/esm/vs/platform/actions/common/actions.js';
14
+ import { INotificationService } from 'monaco-editor/esm/vs/platform/notification/common/notification.js';
15
+ import { ContextKeyExpr } from 'monaco-editor/esm/vs/platform/contextkey/common/contextkey.js';
16
+ import { NOTEBOOK_EDITOR_EDITABLE } from 'vscode/vscode/vs/workbench/contrib/notebook/common/notebookContextKeys';
17
+ import { EditorContextKeys } from 'monaco-editor/esm/vs/editor/common/editorContextKeys.js';
18
+ import { Schemas } from 'monaco-editor/esm/vs/base/common/network.js';
19
+ import { IConfigurationService } from 'monaco-editor/esm/vs/platform/configuration/common/configuration.js';
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: { value: ( localizeWithPath(
128
+ 'vs/workbench/contrib/languageDetection/browser/languageDetection.contribution',
129
+ 'detectlang',
130
+ 'Detect Language from Content'
131
+ )), original: 'Detect Language from Content' },
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
+ });