提供i18n和entityJump的开启和关闭配置
This commit is contained in:
parent
56b7b08389
commit
0c10a720c9
16
package.json
16
package.json
|
|
@ -65,6 +65,22 @@
|
||||||
"when": "false"
|
"when": "false"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
|
"configuration": {
|
||||||
|
"type": "object",
|
||||||
|
"title": "OAK Assistant",
|
||||||
|
"properties": {
|
||||||
|
"oak-assistant.i18n": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"description": "启用国际化相关功能"
|
||||||
|
},
|
||||||
|
"oak-assistant.entityJump": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": true,
|
||||||
|
"description": "启用实体跳转功能"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"menus": {
|
"menus": {
|
||||||
"explorer/context": [
|
"explorer/context": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -145,6 +145,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
activateOakLocale(context);
|
activateOakLocale(context);
|
||||||
activateOakComponentPropsLinkProvider(context);
|
activateOakComponentPropsLinkProvider(context);
|
||||||
commonCommands.activate(context);
|
commonCommands.activate(context);
|
||||||
|
entityProviders.activate(context);
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
helloOak,
|
helloOak,
|
||||||
reload,
|
reload,
|
||||||
|
|
@ -156,7 +157,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
oakPathCompletion.oakPathCompletion,
|
oakPathCompletion.oakPathCompletion,
|
||||||
oakPathCompletion.oakPathDocumentLinkProvider,
|
oakPathCompletion.oakPathDocumentLinkProvider,
|
||||||
...oakPathHighlighter,
|
...oakPathHighlighter,
|
||||||
entityProviders.documentLinkProvider
|
|
||||||
);
|
);
|
||||||
createFileWatcher(context);
|
createFileWatcher(context);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,26 @@
|
||||||
import * as vscode from 'vscode';
|
import * as vscode from 'vscode';
|
||||||
import { entityConfig } from '../utils/entities';
|
import { entityConfig } from '../utils/entities';
|
||||||
|
|
||||||
|
let provider: vscode.Disposable | undefined;
|
||||||
|
|
||||||
const entityProviders = {
|
const entityProviders = {
|
||||||
documentLinkProvider: vscode.languages.registerDocumentLinkProvider(
|
activate: (context: vscode.ExtensionContext) => {
|
||||||
|
const enabled = vscode.workspace
|
||||||
|
.getConfiguration('oak-assistant')
|
||||||
|
.get('entityJump');
|
||||||
|
if (!enabled) {
|
||||||
|
console.log('Entity Jump is disabled');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
provider = vscode.languages.registerDocumentLinkProvider(
|
||||||
{ scheme: 'file' },
|
{ scheme: 'file' },
|
||||||
{
|
{
|
||||||
provideDocumentLinks(
|
provideDocumentLinks(
|
||||||
document: vscode.TextDocument
|
document: vscode.TextDocument
|
||||||
): vscode.DocumentLink[] {
|
): vscode.DocumentLink[] {
|
||||||
const links: vscode.DocumentLink[] = [];
|
const links: vscode.DocumentLink[] = [];
|
||||||
const regex = /[\$]?entity[:=]\s*(['"])([a-zA-Z0-9_\s]+)\1[,\n]/g;
|
const regex =
|
||||||
|
/[\$]?entity[:=]\s*(['"])([a-zA-Z0-9_\s]+)\1[,\n]/g;
|
||||||
const text = document.getText();
|
const text = document.getText();
|
||||||
let match;
|
let match;
|
||||||
while ((match = regex.exec(text)) !== null) {
|
while ((match = regex.exec(text)) !== null) {
|
||||||
|
|
@ -34,11 +45,32 @@ const entityProviders = {
|
||||||
return links;
|
return links;
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
),
|
);
|
||||||
|
context.subscriptions.push(provider);
|
||||||
|
},
|
||||||
dispose() {
|
dispose() {
|
||||||
this.documentLinkProvider.dispose();
|
provider?.dispose();
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// 监控配置修改
|
||||||
|
vscode.workspace.onDidChangeConfiguration((e) => {
|
||||||
|
if (e.affectsConfiguration('oak-assistant.entityJump')) {
|
||||||
|
// 提示重新加载
|
||||||
|
vscode.window
|
||||||
|
.showInformationMessage(
|
||||||
|
'配置已更新,是否重新加载以应用更改?',
|
||||||
|
'是',
|
||||||
|
'否'
|
||||||
|
)
|
||||||
|
.then((selection) => {
|
||||||
|
if (selection === '是') {
|
||||||
|
vscode.commands.executeCommand(
|
||||||
|
'workbench.action.reloadWindow'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default entityProviders;
|
export default entityProviders;
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,4 @@
|
||||||
|
import { getAvailableKeys } from './../utils/locales';
|
||||||
import { join } from 'path';
|
import { join } from 'path';
|
||||||
import {
|
import {
|
||||||
getCachedLocaleItemByKey,
|
getCachedLocaleItemByKey,
|
||||||
|
|
@ -294,6 +295,13 @@ const addLocaleToData = (
|
||||||
};
|
};
|
||||||
|
|
||||||
export function activateOakLocale(context: vscode.ExtensionContext) {
|
export function activateOakLocale(context: vscode.ExtensionContext) {
|
||||||
|
const enabledI18n = vscode.workspace
|
||||||
|
.getConfiguration('oak-assistant')
|
||||||
|
.get('i18n');
|
||||||
|
if (!enabledI18n) {
|
||||||
|
console.log('i18n 相关功能已禁用');
|
||||||
|
return;
|
||||||
|
}
|
||||||
context.subscriptions.push(oakLocalesProvider);
|
context.subscriptions.push(oakLocalesProvider);
|
||||||
context.subscriptions.push(documentChangeListener);
|
context.subscriptions.push(documentChangeListener);
|
||||||
context.subscriptions.push(documentOpenListener);
|
context.subscriptions.push(documentOpenListener);
|
||||||
|
|
@ -314,6 +322,26 @@ export function deactivateOakLocale() {
|
||||||
addLocaleCommand.dispose();
|
addLocaleCommand.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 监控配置项修改
|
||||||
|
vscode.workspace.onDidChangeConfiguration((event) => {
|
||||||
|
if (event.affectsConfiguration('oak-assistant.i18n')) {
|
||||||
|
// 提示重新加载
|
||||||
|
vscode.window
|
||||||
|
.showInformationMessage(
|
||||||
|
'配置已更新,是否重新加载以应用更改?',
|
||||||
|
'是',
|
||||||
|
'否'
|
||||||
|
)
|
||||||
|
.then((selection) => {
|
||||||
|
if (selection === '是') {
|
||||||
|
vscode.commands.executeCommand(
|
||||||
|
'workbench.action.reloadWindow'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
onEntityLoaded(() => {
|
onEntityLoaded(() => {
|
||||||
// 第一次加载完先激活一次
|
// 第一次加载完先激活一次
|
||||||
if (vscode.window.activeTextEditor) {
|
if (vscode.window.activeTextEditor) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue