Skip to content

Commit 010d2b9

Browse files
committed
initAddress
1 parent 57e7330 commit 010d2b9

File tree

3 files changed

+27
-12
lines changed

3 files changed

+27
-12
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@
8686
"default": true,
8787
"description": "Auto apply style sheet"
8888
},
89+
"qsseditor.serverHost": {
90+
"type": "string",
91+
"default": "127.0.0.1",
92+
"description": "DesignerProxy Host"
93+
},
8994
"qsseditor.serverPort": {
9095
"type": "integer",
9196
"default": 61052,

src/client.js

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ var g_timerConnect; // 重连定时器
77
var g_timerApply; // 延迟应用样式
88
var g_autoApply = true; // 是否启用自动应用样式
99
var g_valid = true;
10+
var g_host = "localhost";
1011
var g_port = 61052;
1112
var g_zh = false;
1213

@@ -22,6 +23,14 @@ function initKeywords(context) {
2223
keywords.register(context);
2324
};
2425

26+
/**
27+
* 初始化服务端地址和端口
28+
*/
29+
function initAddress() {
30+
g_host = vscode.workspace.getConfiguration().get('qsseditor.serverHost', '127.0.0.1');
31+
g_port = Number(vscode.workspace.getConfiguration().get('qsseditor.serverPort', '61052'));
32+
};
33+
2534
/**
2635
* 启动客户端
2736
*/
@@ -32,7 +41,9 @@ function startClient() {
3241
g_timerConnect = undefined;
3342
}
3443
if (!g_valid) return;
35-
g_client = new RpcWebSocket('ws://localhost:' + g_port, {
44+
45+
initAddress();
46+
g_client = new RpcWebSocket('ws://' + g_host + ':' + g_port, {
3647
reconnect: false
3748
});
3849
g_client.on('open', function () {
@@ -61,6 +72,14 @@ function stopClient() {
6172
if (g_client != undefined) g_client.close();
6273
};
6374

75+
/**
76+
* 选中控件
77+
*/
78+
function selectWidget(word) {
79+
if (g_client == undefined) return;
80+
g_client.notify('selectWidget', [word]);
81+
};
82+
6483
/**
6584
* 应用样式
6685
*/
@@ -93,13 +112,6 @@ function applyStyle(doc) {
93112
g_client.notify('setStyleSheet', styleSheets);
94113
};
95114

96-
/**
97-
* 初始化端口
98-
*/
99-
function initPort(port) {
100-
g_port = port;
101-
};
102-
103115
/**
104116
* 设置端口
105117
*/
@@ -168,8 +180,8 @@ module.exports = {
168180
initKeywords,
169181
startClient,
170182
stopClient,
183+
selectWidget,
171184
applyStyle,
172-
initPort,
173185
setPort,
174186
onDidChangeTextDocument,
175187
onDidSaveTextDocument,

src/extension.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const client = require('./client.js');
1010
function provideDefinition(document, position, token) {
1111
const word = document.getText(document.getWordRangeAtPosition(position));
1212
if (word.startsWith('Q') || word.startsWith('#')) {
13-
console.log('provideDefinition: ' + word);
13+
client.selectWidget(word);
1414
}
1515
}
1616

@@ -22,8 +22,6 @@ function activate(context) {
2222
console.log('extension "qsseditor" is now active!');
2323
console.log(process.env);
2424

25-
client.initPort(Number(vscode.workspace.getConfiguration().get('qsseditor.serverPort', '61052')));
26-
2725
// 注册命令应用样式命令
2826
context.subscriptions.push(vscode.commands.registerCommand('qsseditor.applyStyle', function () {
2927
client.applyStyle();

0 commit comments

Comments
 (0)