Skip to content

Commit

Permalink
1.2.7
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaoxustudio committed Mar 20, 2024
1 parent c2c2cc3 commit 1ca64ac
Show file tree
Hide file tree
Showing 17 changed files with 354 additions and 103 deletions.
1 change: 1 addition & 0 deletions .vscodeignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
.vscode/**
.vscode-test/**
src/**
/example/**
.gitignore
.yarnrc
vsc-extension-quickstart.md
Expand Down
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
* @Author: xuranXYS
* @LastEditTime: 2024-03-19 20:30:35
* @LastEditTime: 2024-03-20 23:02:26
* @GitHub: www.github.com/xiaoxustudio
* @WebSite: www.xiaoxustudio.top
* @Description: By xuranXYS
Expand All @@ -13,7 +13,15 @@ Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how

## [Unreleased]

## [1.2.6] - 2024.3.19
## [1.2.7] - 2024.3.20

- 修复0003警告
- 优化警告信息截取
- 增加示例
- 格式化优化
- 增加跳转定义功能

## [1.2.6] - 2024.3.20

- 修复工作区lsp不启用的bug
- 优化操作
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<!--
* @Author: xuranXYS
* @LastEditTime: 2024-03-19 18:15:29
* @LastEditTime: 2024-03-20 17:04:51
* @GitHub: www.github.com/xiaoxustudio
* @WebSite: www.xiaoxustudio.top
* @Description: By xuranXYS
Expand Down Expand Up @@ -71,4 +71,4 @@

联系方式:[[email protected]](emailto://[email protected])

欢迎提您提出**issue**
欢迎提出您宝贵的 **issue**,我们将会处理。
12 changes: 12 additions & 0 deletions example/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@


callScene: start.txt;


; 颜色测试
#FA0099
rgba(255,255,120,255)
rgba(240,255,200)



14 changes: 14 additions & 0 deletions example/format.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@

intro:测试 -name=测试 -name=测试;
callScene:start.txt -name=测试;
callScene:start.txt;
callScene:start.txt;
callScene:start.txt;
callScene:start.txt;
callScene:start.txt;
callScene: -name=测试;

callScene:start.txt;
callScene:start.txt;
callScene:start.txt;

15 changes: 15 additions & 0 deletions example/variableJump.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
setVar:a=123;




setVar:b=123;






{b}

{a}
15 changes: 15 additions & 0 deletions example/warning.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; 警告测试
{ a}
{a }
{ a }

; 指令:前无空格
intro:测试;

; 变量名称前导数字
setVar:00test=123;

; 参数前面包含一个以上的空格
intro: 测试 -name;


13 changes: 9 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "webgal-for-vscode",
"displayName": "webgal for VSCode",
"description": "webgal-for-vscode by xuran",
"version": "1.2.6",
"version": "1.2.7",
"repository": {
"type": "git",
"url": "https://github.com/xiaoxustudio/webgal-for-vscode"
Expand Down Expand Up @@ -41,10 +41,15 @@
"configuration": "src/config/language-configuration.json"
}
],
"commands": [],
"commands": [
{
"title": "跳转到插值变量",
"command": "extension.goToDefinition"
}
],
"configuration": {
"type": "object",
"title": "Example configuration",
"title": "wabgal configuration",
"properties": {
"XRWebGalLanguageServer.maxNumberOfProblems": {
"scope": "resource",
Expand Down Expand Up @@ -99,4 +104,4 @@
"devDependencies": {
"@types/node": "^20.11.30"
}
}
}
106 changes: 53 additions & 53 deletions src/HoverProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* @Author: xuranXYS
* @LastEditTime: 2024-03-20 12:17:27
* @LastEditTime: 2024-03-20 22:59:51
* @GitHub: www.github.com/xiaoxustudio
* @WebSite: www.xiaoxustudio.top
* @Description: By xuranXYS
Expand All @@ -9,12 +9,51 @@ import * as vscode from "vscode";
import { dictionary } from "./config/HoverSnippet";
import { _setvar_pattern } from "./CompletionProvider";

interface _VToken {
export interface _VToken {
word: string;
type?: string;
is_global?: boolean;
position?: vscode.Position;
input?: string;
}
export function _find_variable_type(sources: string, _w: string, _arr: any) {
let _find = /setVar:\s*(\w+)\s*=\s*([^;]*\S+);?/g.exec(sources);
if (!_find || _find[1].trim() !== _w.trim()) {
_arr[_w].type = "未知";
return;
}
const _is_global = _find[2].indexOf("-global") !== -1 ? true : false;
let _val;
if (_is_global) {
_val = _find[2].substring(
_find[2].indexOf("="),
_find[2].lastIndexOf(" -")
);
} else {
_val = _find[2].substring(_find[2].indexOf("="), _find[2].lastIndexOf(";"));
}
try {
const __val_real = new Function("return " + _val)();
switch (typeof __val_real) {
case "number":
_arr[_w].type = "数字";
break;
case "boolean":
_arr[_w].type = "布尔值";
break;
default:
_arr[_w].type = "字符串";
break;
}
} catch {
if (typeof new Function(`return '${_val}'`)() === "string") {
_arr[_w].type = "字符串";
} else {
_arr[_w].type = "未知";
}
}
return;
}

export default class DictionaryHoverProvider implements vscode.HoverProvider {
provideHover(
document: vscode.TextDocument,
Expand All @@ -26,55 +65,17 @@ export default class DictionaryHoverProvider implements vscode.HoverProvider {
const _arr: { [key: string]: _VToken } = {};
const _arrType = [];
let m;
const _find_variable_type = (sources: string, _w: string) => {
let _find = /setVar:\s*(\w+)\s*=\s*([^;]*\S+);?/g.exec(sources);
if (!_find || _find[1].trim() !== _w.trim()) {
_arr[_w].type = "未知";
return;
}
const _is_global = _find[2].indexOf("-global") !== -1 ? true : false;
let _val;
if (_is_global) {
_val = _find[2].substring(
_find[2].indexOf("="),
_find[2].lastIndexOf(" -")
);
} else {
_val = _find[2].substring(
_find[2].indexOf("="),
_find[2].lastIndexOf(";")
);
}
try {
const __val_real = new Function("return " + _val)();
switch (typeof __val_real) {
case "number":
_arr[_w].type = "数字";
break;
case "boolean":
_arr[_w].type = "布尔值";
break;
default:
_arr[_w].type = "字符串";
break;
}
} catch {
if (typeof new Function(`return '${_val}'`)() === "string") {
_arr[_w].type = "字符串";
} else {
_arr[_w].type = "未知";
}
}
return;
};
const ALL_ARR = document.getText().split("\n");
for (let _data of ALL_ARR) {
for (let _d_index = 0; _d_index < ALL_ARR.length; _d_index++) {
const _data = ALL_ARR[_d_index];
let m = /setVar:\s*(\w+)\s*=\s*([^;]*\S+);?/g.exec(_data);
if (m) {
_arr[m[1]] = {
word: m[1],
input: m.input,
position: position.with(_d_index + 1, 5),
} as _VToken;
_arrType.push(_find_variable_type(m.input, m[1]));
_arrType.push(_find_variable_type(m.input, m[1], _arr));
}
}
// 获取上下文全部变量
Expand All @@ -92,7 +93,9 @@ export default class DictionaryHoverProvider implements vscode.HoverProvider {
hoverContent.appendMarkdown(
`\n\n Type : <span style="color:#f00;">**${_arr[word].type}**</span>`
);
hoverContent.appendMarkdown(`\n\n position : 位于第${position.line}行`);
hoverContent.appendMarkdown(
`\n\n position : 位于第${_arr[word].position?.line}行`
);
} else {
hoverContent.appendMarkdown(`\n\n 未定义变量`);
}
Expand Down Expand Up @@ -135,13 +138,10 @@ export default class DictionaryHoverProvider implements vscode.HoverProvider {
return hover;
}
}
} else {
} else if (pos) {
const beforepos = new vscode.Range(
new vscode.Position(
pos?.start.line || 0,
pos?.start.character! - 1 || 0
),
pos?.start! || 0
new vscode.Position(pos.start.line || 0, pos.start.character! - 1 || 0),
pos.start! || 0
);
let _s = document.getText(beforepos);
const _d_cmd = dictionary.cmd[word];
Expand Down
76 changes: 76 additions & 0 deletions src/XRDefinitionProvider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* @Author: xuranXYS
* @LastEditTime: 2024-03-20 23:01:22
* @GitHub: www.github.com/xiaoxustudio
* @WebSite: www.xiaoxustudio.top
* @Description: By xuranXYS
*/
import * as vscode from "vscode";
import { selector } from "./utils";
import {
CancellationToken,
Definition,
DefinitionProvider,
Position,
TextDocument,
} from "vscode";
import { _find_variable_type, _VToken } from "./HoverProvider";

export class XRDefinitionProvider implements DefinitionProvider {
provideDefinition(
document: TextDocument,
position: Position,
token: CancellationToken
) {
const _arr: { [key: string]: _VToken } = {};
const ALL_ARR = document.getText().split("\n");
const _ALL_ARR_cache = [];
const _arrType = [];
for (let _d_index = 0; _d_index < ALL_ARR.length; _d_index++) {
const _data = ALL_ARR[_d_index];
let m = /setVar:\s*(\w+)\s*=\s*([^;]*\S+);?/g.exec(_data);
if (m) {
_arr[m[1]] = {
word: m[1],
input: m.input,
position: position.with(_d_index, 7),
} as _VToken;
_arrType.push(_find_variable_type(m.input, m[1], _arr));
} else {
_ALL_ARR_cache.push(_data);
}
}
const editor = vscode.window.activeTextEditor;
if (editor) {
const position_select = editor.selection.active;
const wordRange = editor.document.getWordRangeAtPosition(position_select);
if (wordRange) {
const _range = wordRange.with(
wordRange.start.with(
wordRange.start.line,
wordRange.start.character - 1
),
wordRange.end.with(wordRange.end.line, wordRange.end.character + 1)
);
const word = editor.document.getText(_range);
const _length = word.length;
const _word_no = word.substring(word.indexOf("{") + 1, _length - 1);
// 判断是否是有效word
if (/{\S+}/.test(word) && _arr[_word_no]) {
return [
{
uri: document.uri,
range: wordRange.with(
_arr[_word_no].position,
_arr[_word_no].position?.with(
_arr[_word_no].position?.line,
_arr[_word_no].input?.indexOf("=")
)
),
},
] as Definition;
}
}
}
}
}
Loading

0 comments on commit 1ca64ac

Please sign in to comment.