提供i18n和entityJump的开启和关闭配置
This commit is contained in:
parent
56b7b08389
commit
0c10a720c9
16
package.json
16
package.json
|
|
@ -65,6 +65,22 @@
|
|||
"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": {
|
||||
"explorer/context": [
|
||||
{
|
||||
|
|
|
|||
|
|
@ -145,6 +145,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
activateOakLocale(context);
|
||||
activateOakComponentPropsLinkProvider(context);
|
||||
commonCommands.activate(context);
|
||||
entityProviders.activate(context);
|
||||
context.subscriptions.push(
|
||||
helloOak,
|
||||
reload,
|
||||
|
|
@ -156,7 +157,6 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||
oakPathCompletion.oakPathCompletion,
|
||||
oakPathCompletion.oakPathDocumentLinkProvider,
|
||||
...oakPathHighlighter,
|
||||
entityProviders.documentLinkProvider
|
||||
);
|
||||
createFileWatcher(context);
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -1,44 +1,76 @@
|
|||
import * as vscode from 'vscode';
|
||||
import { entityConfig } from '../utils/entities';
|
||||
|
||||
const entityProviders = {
|
||||
documentLinkProvider: vscode.languages.registerDocumentLinkProvider(
|
||||
{ scheme: 'file' },
|
||||
{
|
||||
provideDocumentLinks(
|
||||
document: vscode.TextDocument
|
||||
): vscode.DocumentLink[] {
|
||||
const links: vscode.DocumentLink[] = [];
|
||||
const regex = /[\$]?entity[:=]\s*(['"])([a-zA-Z0-9_\s]+)\1[,\n]/g;
|
||||
const text = document.getText();
|
||||
let match;
|
||||
while ((match = regex.exec(text)) !== null) {
|
||||
const entityName = match[2];
|
||||
if (!entityConfig.entityNameList.includes(entityName)) {
|
||||
continue;
|
||||
}
|
||||
const start = document.positionAt(match.index);
|
||||
const end = document.positionAt(
|
||||
match.index + match[0].length
|
||||
);
|
||||
const range = new vscode.Range(start, end);
|
||||
const uri = vscode.Uri.parse(
|
||||
`command:oak-entities.jumpToDefinition?${encodeURIComponent(
|
||||
JSON.stringify({ entityName })
|
||||
)}`
|
||||
);
|
||||
const link = new vscode.DocumentLink(range, uri);
|
||||
link.tooltip = `跳转到定义: ${entityName}`;
|
||||
links.push(link);
|
||||
}
|
||||
return links;
|
||||
},
|
||||
}
|
||||
),
|
||||
let provider: vscode.Disposable | undefined;
|
||||
|
||||
const entityProviders = {
|
||||
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' },
|
||||
{
|
||||
provideDocumentLinks(
|
||||
document: vscode.TextDocument
|
||||
): vscode.DocumentLink[] {
|
||||
const links: vscode.DocumentLink[] = [];
|
||||
const regex =
|
||||
/[\$]?entity[:=]\s*(['"])([a-zA-Z0-9_\s]+)\1[,\n]/g;
|
||||
const text = document.getText();
|
||||
let match;
|
||||
while ((match = regex.exec(text)) !== null) {
|
||||
const entityName = match[2];
|
||||
if (!entityConfig.entityNameList.includes(entityName)) {
|
||||
continue;
|
||||
}
|
||||
const start = document.positionAt(match.index);
|
||||
const end = document.positionAt(
|
||||
match.index + match[0].length
|
||||
);
|
||||
const range = new vscode.Range(start, end);
|
||||
const uri = vscode.Uri.parse(
|
||||
`command:oak-entities.jumpToDefinition?${encodeURIComponent(
|
||||
JSON.stringify({ entityName })
|
||||
)}`
|
||||
);
|
||||
const link = new vscode.DocumentLink(range, uri);
|
||||
link.tooltip = `跳转到定义: ${entityName}`;
|
||||
links.push(link);
|
||||
}
|
||||
return links;
|
||||
},
|
||||
}
|
||||
);
|
||||
context.subscriptions.push(provider);
|
||||
},
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import { getAvailableKeys } from './../utils/locales';
|
||||
import { join } from 'path';
|
||||
import {
|
||||
getCachedLocaleItemByKey,
|
||||
|
|
@ -294,6 +295,13 @@ const addLocaleToData = (
|
|||
};
|
||||
|
||||
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(documentChangeListener);
|
||||
context.subscriptions.push(documentOpenListener);
|
||||
|
|
@ -314,6 +322,26 @@ export function deactivateOakLocale() {
|
|||
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(() => {
|
||||
// 第一次加载完先激活一次
|
||||
if (vscode.window.activeTextEditor) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue