Skip to content

Commit

Permalink
add Web IDE complete function for Yuescript with statement.
Browse files Browse the repository at this point in the history
  • Loading branch information
pigpigyyy committed Dec 19, 2023
1 parent 8efc078 commit 1367b66
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 11 deletions.
13 changes: 10 additions & 3 deletions Assets/Script/Lib/WebServer.yue
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,6 @@ getCompiledYueLine = (content, line, row, file)->
if row == lastLine and not targetLine
targetRow = current
targetLine = line\gsub("::", "\\")\gsub(":", "=")\gsub("\\", ":")\match "[%w_%.:]+$"
if targetLine and targetLine\match "^[%.:]"
targetLine = lineCode\match "[%w_%.:]+[%.:]#{targetLine\sub 2, -1}"
break if targetLine
current += 1
if targetLine and targetRow
Expand Down Expand Up @@ -277,6 +275,9 @@ HttpServer\postSchedule "/signature", (req)->
when "yue"
luaCodes, targetLine, targetRow, lineMap = getCompiledYueLine content, line, row, file
return success: false unless luaCodes
if chainOp, chainCall := line\match "[^%w_]([%.\\])([^%.\\]+)$"
withVar = luaCodes\match "([%w_]+)%.___DUMMY_CALL___%(%)"
targetLine = withVar .. (chainOp == '\\' and ':' or '.') .. chainCall
if signatures := teal.getSignatureAsync luaCodes, targetLine, targetRow, searchPath
if signatures := getParamDocs signatures
return success: true, :signatures
Expand Down Expand Up @@ -446,10 +447,16 @@ HttpServer\postSchedule "/complete", (req)->
gotGlobals = false
if luaCodes, targetLine, targetRow := getCompiledYueLine content, line, row, file
gotGlobals = true
if chainOp := line\match "[^%w_]([%.\\])$"
withVar = luaCodes\match "([%w_]+)%.___DUMMY_CALL___%(%)"
return success: false unless withVar
targetLine = "#{withVar}#{chainOp == '\\' and ':' or '.'}"
elseif line\match "^([%.\\])$"
return success: false
suggestions[] = item for item in *teal.completeAsync luaCodes, targetLine, targetRow, searchPath
if #suggestions == 0
suggestions[] = item for item in *teal.completeAsync luaCodes, "builtin.#{targetLine}", targetRow, searchPath
if not line\match("[%.:\\][%w_]+[%.\\]?$") and not line\match "[%w_]+[%.\\]$"
if not line\match("[%.:\\][%w_]+[%.\\]?$") and not line\match "[%.\\]$"
checkSet = {name, true for {name} in *suggestions}
for item in *teal.completeAsync "", "builtin.", 1, searchPath
suggestions[] = item if not checkSet[item[1]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import "@site/src/languages/highlight";
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';

# 使用Dora Xml编写UI 1
# 使用 Dora Xml 编写 UI 1

  Dorothy SSR 提供了一个可以帮助做图形展示与逻辑处理代码做一些开发分离的功能框架,叫做Dora Xml。Dora Xml的核心功能就是把图形展示和交互的代码,特别是一些游戏UI界面中的关注于用户展示的代码用Xml标记语言来编写,就像Web网页中的HTML语言类似的定位。像创建UI组件,设置布局尺寸、颜色外观,创建交互动画和UI动画响应消息事件,都可以只用Dora Xml语言来组织和完成编写。Dora Xml基本符合Xml规范,但也稍微做了些修改,有很多预定义的标签,也可以自定义新的标签。

Expand Down
3 changes: 2 additions & 1 deletion Source/3rdParty/yuescript/yue_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ static std::unordered_set<std::string> Metamethods = {
"close"s // Lua 5.4
};

const std::string_view version = "0.21.4"sv;
const std::string_view version = "0.21.5"sv;
const std::string_view extension = "yue"sv;

class CompileError : public std::logic_error {
Expand Down Expand Up @@ -3959,6 +3959,7 @@ class YueCompilerImpl {
expListAssign && expListAssign->action && expListAssign->action.is<Assign_t>()) {
BLOCK_START
auto unary = singleUnaryExpFrom(expListAssign->expList->exprs.back());
BREAK_IF(!unary);
BREAK_IF(!unary->ops.empty());
auto value = static_cast<Value_t*>(unary->expos.front());
auto simpleValue = value->item.as<SimpleValue_t>();
Expand Down
6 changes: 3 additions & 3 deletions Source/Lua/Builtin/Class.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ local type = type
-- or
local MyClass = Class(function(args)
return Node()
end,{ ... })
end, { ... })
-- or
local MyClass = Class(Node,{ ... })
local MyClass = Class(Node, { ... })
4.To add class member function
Expand Down Expand Up @@ -159,7 +159,7 @@ local function __newindex(self, name, value)
end

local function assignReadOnly()
error("Try to assign to a readonly property!")
error("try to assign to a readonly property!")
end

local function Class(arg1, arg2)
Expand Down
6 changes: 6 additions & 0 deletions Source/Lua/LuaFromXml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ static const char* _toBoolean(const char* str) {
const char* transformTarget = nullptr; \
const char* visible = nullptr; \
const char* touchEnabled = nullptr; \
const char* controllerEnabled = nullptr; \
const char* swallowTouches = nullptr; \
const char* swallowMouseWheel = nullptr; \
const char* renderGroup = nullptr; \
Expand Down Expand Up @@ -612,6 +613,10 @@ static const char* _toBoolean(const char* str) {
touchEnabled = atts[++i]; \
break; \
} \
CASE_STR(ControllerEnabled) { \
controllerEnabled = atts[++i]; \
break; \
} \
CASE_STR(SwallowTouches) { \
swallowTouches = atts[++i]; \
break; \
Expand Down Expand Up @@ -662,6 +667,7 @@ static const char* _toBoolean(const char* str) {
else if (!width && height) \
fmt::format_to(std::back_inserter(stream), "{}.height = {}{}"sv, self, Val(height), nl()); \
if (touchEnabled) fmt::format_to(std::back_inserter(stream), "{}.touchEnabled = {}{}"sv, self, toBoolean(touchEnabled), nl()); \
if (controllerEnabled) fmt::format_to(std::back_inserter(stream), "{}.controllerEnabled = {}{}"sv, self, toBoolean(controllerEnabled), nl()); \
if (swallowTouches) fmt::format_to(std::back_inserter(stream), "{}.swallowTouches = {}{}"sv, self, toBoolean(swallowTouches), nl()); \
if (swallowMouseWheel) fmt::format_to(std::back_inserter(stream), "{}.swallowMouseWheel = {}{}"sv, self, toBoolean(swallowMouseWheel), nl()); \
if (renderGroup) fmt::format_to(std::back_inserter(stream), "{}.renderGroup = {}{}"sv, self, toBoolean(renderGroup), nl()); \
Expand Down
3 changes: 2 additions & 1 deletion Source/Lua/Xml/DorothyTagText.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Boolean:True,False
LayerParent:Menu
BuiltInSlots:AnimationEnd,ActionEnd,TapFilter,TapBegan,TapEnded,Tapped,TapMoved,MouseWheel,Gesture,Enter,Exit,Cleanup,KeyDown,KeyUp,KeyPressed,AttachIME,DetachIME,TextInput,TextEditing
BuiltInSlots:AnimationEnd,ActionEnd,TapFilter,TapBegan,TapEnded,Tapped,TapMoved,MouseWheel,Gesture,Enter,Exit,Cleanup,KeyDown,KeyUp,KeyPressed,AttachIME,DetachIME,TextInput,TextEditing,ButtonDown,ButtonUp,ButtonPressed,Axis
Import
Base:No
Expand Down Expand Up @@ -199,6 +199,7 @@ Node
TransformTarget
Visible:Boolean
TouchEnabled:Boolean
ControllerEnabled:Boolean
SwallowTouches:Boolean
SwallowMouseWheel:Boolean
RenderGroup:Boolean
Expand Down
34 changes: 32 additions & 2 deletions Tools/dora-dora/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,22 @@ const completionItemProvider = (triggerCharacters: string[], lang: CompleteLang)
} else {
content = "";
}
content += "\n" + "\t".repeat(Math.max(0, model.getLineFirstNonWhitespaceColumn(position.lineNumber) - 1)) + "print()\n" + model.getValueInRange({
let whiteSpace = "";
const start = model.getLineFirstNonWhitespaceColumn(position.lineNumber);
if (start > 0) {
whiteSpace = model.getValueInRange({
startLineNumber: position.lineNumber,
startColumn: 1,
endLineNumber: position.lineNumber,
endColumn: start,
});
}
if (line.match(/\W[\.\\]$/g)) {
content += "\n" + whiteSpace + ".___DUMMY_CALL___()\n";
} else {
content += "\n" + whiteSpace + "print()\n";
}
content += model.getValueInRange({
startLineNumber: position.lineNumber + 1,
startColumn: 1,
endLineNumber: model.getLineCount(),
Expand Down Expand Up @@ -263,7 +278,22 @@ const signatureHelpProvider = (signatureHelpTriggerCharacters: string[], lang: S
} else {
content = "";
}
content += "\n" + "\t".repeat(Math.max(0, model.getLineFirstNonWhitespaceColumn(position.lineNumber) - 1)) + "print()\n" + model.getValueInRange({
let whiteSpace = "";
const start = model.getLineFirstNonWhitespaceColumn(position.lineNumber);
if (start > 0) {
whiteSpace = model.getValueInRange({
startLineNumber: position.lineNumber,
startColumn: 1,
endLineNumber: position.lineNumber,
endColumn: start,
});
}
if (line.match(/\W[\.\\][^\.\\]+$/g)) {
content += "\n" + whiteSpace + ".___DUMMY_CALL___()\n";
} else {
content += "\n" + whiteSpace + "print()\n";
}
content += model.getValueInRange({
startLineNumber: position.lineNumber + 1,
startColumn: 1,
endLineNumber: model.getLineCount(),
Expand Down

0 comments on commit 1367b66

Please sign in to comment.