Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Syntax fixes #439

Merged
merged 6 commits into from
Aug 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions examples/unit_test.rpy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
define s = Character('Sylvie', color="#f44747")
define s = Character('Sylvie', color="#808080")

default name1="foo"
default name2="bar"
default names=list(["[name1]","[name2][[]"])

label start:
$ my_list = ["[name1]]"]

define m = Character('Me', color="#c8c8ff")

image logo = "renpy logo.png"
Expand Down
19 changes: 12 additions & 7 deletions src/diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// Diagnostics (warnings and errors)
import { commands, Diagnostic, DiagnosticCollection, DiagnosticSeverity, Disposable, ExtensionContext, FileType, languages, Range, TextDocument, Uri, window, workspace } from "vscode";
import { commands, Diagnostic, DiagnosticCollection, DiagnosticSeverity, Disposable, ExtensionContext, FileType, languages, LogLevel, Range, TextDocument, Uri, window, workspace } from "vscode";
import { NavigationData } from "./navigation-data";
import { getAllOpenTabInputTextUri } from "./utilities/functions";
import { extractFilename } from "./workspace";
import { LogCategory, logCatMessage } from "./logger";

// Renpy Store Variables (https://www.renpy.org/doc/html/store_variables.html)
// These variables do not begin with '_' but should be ignored by store warnings because they are pre-defined by Ren'Py
Expand Down Expand Up @@ -202,17 +203,21 @@ function refreshDiagnostics(doc: TextDocument, diagnosticCollection: DiagnosticC
function refreshOpenDocuments(diagnosticCollection: DiagnosticCollection) {
diagnosticCollection.clear();
const tabInputTextUris = getAllOpenTabInputTextUri();
tabInputTextUris.forEach((uri) => {
diagnoseFromUri(uri, diagnosticCollection);
tabInputTextUris.forEach(async (uri) => {
await diagnoseFromUri(uri, diagnosticCollection);
});
}

function diagnoseFromUri(uri: Uri, diagnosticCollection: DiagnosticCollection) {
workspace.fs.stat(uri).then((stat) => {
if (stat.type === FileType.File) {
async function diagnoseFromUri(uri: Uri, diagnosticCollection: DiagnosticCollection) {
try {
const fileInfo = await workspace.fs.stat(uri);

if (fileInfo.type === FileType.File) {
workspace.openTextDocument(uri).then((document) => refreshDiagnostics(document, diagnosticCollection));
}
});
} catch (error) {
logCatMessage(LogLevel.Error, LogCategory.Default, error as string);
}
}

function onDeleteFromWorkspace(uri: Uri, diagnosticCollection: DiagnosticCollection) {
Expand Down
1 change: 1 addition & 0 deletions syntaxes/renpy.atl.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,7 @@
"name": "entity.name.type.transform.renpy",
"match": "\\b([[:alpha:]_]\\w*)\\b"
},
{ "include": "source.renpy.python#parameters" },
{ "include": "source.renpy#whitespace" }
]
}
Expand Down
6 changes: 3 additions & 3 deletions syntaxes/renpy.python.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -1996,11 +1996,11 @@
},
"string-quoted-single-line": {
"name": "string.quoted.single.python",
"begin": "(\\b[rRuU])?(\\b\\w+)?(['\"])",
"begin": "(?:\\b([rR])(?=[uU]))?([uU])?(['\"])",
"end": "(\\3)|((?<!\\\\)\\n)",
"beginCaptures": {
"1": { "name": "storage.type.string.python" },
"2": { "name": "invalid.illegal.prefix.python" },
"1": { "name": "invalid.illegal.prefix.python" },
"2": { "name": "storage.type.string.python" },
"3": { "name": "punctuation.definition.string.begin.python" }
},
"endCaptures": {
Expand Down
68 changes: 29 additions & 39 deletions syntaxes/renpy.screen.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
{
"comment": "Special manipulation keywords",
"name": "keyword.control.flow.renpy",
"match": "\\b(?<!\\.)(?:action|at|(?:un)?hovered|alt|value|dragged)\\b"
"match": "\\b(?<!\\.)(?:action|at|(?:un)?hovered|alt|value|dragged|released)\\b"
},
{
"comment": "Special manipulation keywords",
"match": "\\b(?<!\\.)(key|input|(?:text|image)?button|grid|auto|mousearea|side|timer|[vh]?bar|action|viewport|(?:vp)?grid|imagemap|hotspot|hotbar|transclude)\\b",
"match": "\\b(?<!\\.)(key|default|input|(?:text|image)?button|grid|auto|mousearea|side|timer|[vh]?bar|action|viewport|(?:vp)?grid|imagemap|hotspot|hotbar|transclude)\\b",
"captures": {
"1": { "name": "keyword.other.renpy" }
}
Expand Down Expand Up @@ -190,11 +190,11 @@
},
{
"name": "keyword.other.renpy",
"match": "\\b(?<!\\.)(?:sensitive|tag|text|drag|draggroup|id|test)\\b"
"match": "\\b(?<!\\.)(?:sensitive|tag|text|drag|draggroup|id|test|style)\\b[^\\.]"
},
{
"name": "entity.other.attribute-name.transform.renpy entity.name.tag.css.transform.renpy",
"match": "\\b(?<!\\.)(?:modal|style|style_group|style_prefix|zorder|tooltip|variant|layer|roll_forward)\\b"
"match": "\\b(?<!\\.)(?:modal|style_group|style_prefix|zorder|tooltip|variant|layer|roll_forward)\\b"
},
{
"name": "keyword.other.renpy",
Expand All @@ -206,14 +206,26 @@
"patterns": [
{
"contentName": "meta.screen.block.renpy",
"begin": "(?<=(^[ \\t]*)(?:screen|frame|fixed|window|viewport|drag|draggroup|(?:vp)?grid|text|vbox|hbox|imagemap)\\b.*?)(:)",
"begin": "(?<=(^[ \\t]*)(?:screen|frame|fixed|window|viewport|drag|draggroup|(?:vp)?grid|vbox|hbox|imagemap)\\b.*?)(:)",
"beginCaptures": {
"2": { "name": "punctuation.section.screen.begin.renpy" }
},
"end": "^(?=(?!\\1)[ \\t]*[^\\s#]|\\1[^\\s#])",
"patterns": [
{ "include": "#screen-language" }
]
},
{
"contentName": "meta.atl.block.renpy",
"begin": "(?<=(^[ \\t]*)(?:text)\\b.*?)(:)",
"beginCaptures": {
"2": { "name": "punctuation.section.atl.begin.renpy" }
},
"end": "^(?=(?!\\1)[ \\t]*[^\\s#]|\\1[^\\s#])",
"patterns": [
{ "include": "#screen-language" },
{ "include": "source.renpy.atl" }
]
}
]
},
Expand All @@ -240,45 +252,22 @@
}
},
"screen-text": {
"contentName": "meta.screen.text.renpy",
"begin": "^([ \\t]+)?(text)\\b[ \\t]*(:)",
"name": "meta.screen.text.renpy",
"begin": "(?<=^[ \\t]*)(text)\\b",
"beginCaptures": {
"1": { "name": "punctuation.whitespace.leading.block.renpy" },
"2": { "name": "keyword.text.renpy" },
"3": { "name": "punctuation.section.block.begin.renpy" }
"1": { "name": "keyword.text.renpy" }
},
"end": "^(?=(?!\\1)[ \\t]*[^\\s#]|\\1[^\\s#])",

"end": "(?=:)|$",
"patterns": [
{ "include": "source.renpy#strings" },
{
"name": "meta.screen.text.renpy",
"contentName": "meta.atl-block.renpy",
"begin": "^([ \\t]+)?(text)\\b[ \\t]*([a-zA-Z_0-9 ]*)(:)",
"beginCaptures": {
"1": { "name": "punctuation.whitespace.leading.renpy" },
"2": { "name": "keyword.text.renpy" },
"3": { "name": "entity.name.type.text.renpy" },
"4": { "name": "punctuation.section.atl.begin.renpy" }
},
"end": "^(?=(?!\\1)[ \\t]*[^\\s#]|\\1[^\\s#])",
"patterns": [ { "include": "source.renpy.atl" } ]
"match": "(?<=text[ \\t]*)\\b(?:[a-zA-Z_0-9]+)\\b(?=[ \\t]+|$)",
"name": "entity.name.type.text.renpy"
},
{
"name": "meta.screen.text.renpy",
"begin": "(?<=^[ \\t]*)(text)\\b[ \\t]*",
"beginCaptures": {
"1": { "name": "keyword.text.renpy" }
},
"end": "(?=\\b(at)\\b|#|=)|$",
"patterns": [
{ "include": "source.renpy#strings" },
{
"match": "\\b(?:[a-zA-Z_0-9]+)\\b[ \\t]*",
"name": "entity.name.type.text.renpy"
}
]
},
{ "include": "source.renpy#at-statement" }
{ "include": "source.renpy#at-statement" },
{ "include": "#screen-keywords" },
{ "include": "#screen-simple-expression" },
{ "include": "source.renpy#fallback-patterns" }
]
},
"screen-box": {
Expand Down Expand Up @@ -337,6 +326,7 @@
{ "include": "#screen-window" },
{ "include": "#screen-box" },
{ "include": "#screen-text" },
{ "include": "#screen-block-tester" },
{ "include": "#screen-keywords" },
{ "include": "#screen-simple-expression" },
{ "include": "#screen-fallback" }
Expand Down
21 changes: 18 additions & 3 deletions syntaxes/renpy.style.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
"scopeName": "source.renpy.style",
"patterns": [ { "include": "#style" } ],
"repository": {
"builtin-styles": {
"patterns": [
{
"name": "support.type.builtin.style.renpy",
"match": "\\b(?<!\\.)(?:(alt)?ruby_style)\\b"
}
]
},

"style-block-tester": {
"patterns": [
{
Expand All @@ -27,7 +36,11 @@
{
"comment": "ON EDIT: If you update this list, also update it in style-clause",
"name": "support.constant.property-key.test.renpy entity.name.tag.css.style.renpy",
"match": "\\b(?<!\\.)(?:(?:selected_)?(?:hover_|idle_|insensitive_|activate_)?(?:activate_sound|adjust_spacing|aft_bar|aft_gutter|alt|altruby_style|antialias|axis|background|bar_invert|bar_resizing|unscrollable|bar_vertical|black_color|bold|bottom_margin|bottom_padding|box_layout|box_reverse|box_wrap|box_wrap_spacing|caret|child|clipping|color|debug|drop_shadow|drop_shadow_color|emoji_font|extra_alt|first_indent|first_spacing|fit_first|focus_mask|focus_rect|font|fore_bar|fore_gutter|foreground|group_alt|hinting|hover_sound|hyperlink_functions|italic|instance|justify|kerning|key_events|keyboard_focus|language|layout|line_leading|left_margin|line_overlap_split|left_padding|line_spacing|mouse|modal|min_width|mipmap|newline_indent|order_reverse|outlines|outline_scaling|prefer_emoji|rest_indent|right_margin|right_padding|ruby_line_leading|ruby_style|shaper|size|size_group|slow_abortable|slow_cps|slow_cps_multiplier|spacing|strikethrough|subtitle_width|subpixel|text_y_fudge|text_align|thumb|thumb_offset|thumb_shadow|time_policy|top_margin|top_padding|underline|vertical|xanchor|xfill|xfit|xmaximum|xminimum|xoffset|xpos|xspacing|yanchor|yfill|yfit|ymaximum|yminimum|yoffset|ypos|yspacing|margin|xmargin|ymargin|xalign|yalign|padding|xpadding|ypadding|minwidth|textalign|slow_speed|enable_hover|left_gutter|right_gutter|top_gutter|bottom_gutter|left_bar|right_bar|top_bar|bottom_bar|base_bar|box_spacing|box_first_spacing|pos|anchor|offset|align|maximum|minimum|xsize|ysize|xysize|area|xcenter|ycenter|xycenter))\\b"
"match": "\\b(?<!\\.)(?:(?:selected_)?(?:hover_|idle_|insensitive_|activate_)?(?:activate_sound|adjust_spacing|aft_bar|aft_gutter|alt|antialias|axis|background|bar_invert|bar_resizing|unscrollable|bar_vertical|black_color|bold|bottom_margin|bottom_padding|box_layout|box_reverse|box_wrap|box_wrap_spacing|caret|child|clipping|color|debug|drop_shadow|drop_shadow_color|emoji_font|extra_alt|first_indent|first_spacing|fit_first|focus_mask|focus_rect|font|fore_bar|fore_gutter|foreground|group_alt|hinting|hover_sound|hyperlink_functions|italic|instance|justify|kerning|key_events|keyboard_focus|language|layout|line_leading|left_margin|line_overlap_split|left_padding|line_spacing|mouse|modal|min_width|mipmap|newline_indent|order_reverse|outlines|outline_scaling|prefer_emoji|rest_indent|right_margin|right_padding|ruby_line_leading|shaper|size|size_group|slow_abortable|slow_cps|slow_cps_multiplier|spacing|strikethrough|subtitle_width|subpixel|text_y_fudge|text_align|thumb|thumb_offset|thumb_shadow|time_policy|top_margin|top_padding|underline|vertical|xanchor|xfill|xfit|xmaximum|xminimum|xoffset|xpos|xspacing|yanchor|yfill|yfit|ymaximum|yminimum|yoffset|ypos|yspacing|margin|xmargin|ymargin|xalign|yalign|padding|xpadding|ypadding|minwidth|textalign|slow_speed|enable_hover|left_gutter|right_gutter|top_gutter|bottom_gutter|left_bar|right_bar|top_bar|bottom_bar|base_bar|box_spacing|box_first_spacing|pos|anchor|offset|align|maximum|minimum|xsize|ysize|xysize|area|xcenter|ycenter|xycenter))\\b"
},
{
"name": "support.type.builtin.style.renpy",
"match": "\\b(?<!\\.)(?:(alt)?ruby_style)\\b"
},
{
"name": "support.constant.property-key.renpy entity.name.tag.css.style.renpy",
Expand Down Expand Up @@ -111,11 +124,13 @@
"end": "$|^",

"patterns": [
{ "include": "#style-clause" },
{ "include": "#builtin-styles" },
{
"comment": "Only the first identifier is a style name",
"name": "entity.name.type.style.renpy",
"match": "\\b[\\p{XID_Start}_]\\p{XID_Continue}*\\b"
"match": "(?<=\\bstyle[ \\t]*)\\b[\\p{XID_Start}_]\\p{XID_Continue}*\\b"
},
{ "include": "#style-clause" },
{ "include": "#style-block-tester" },
{ "include": "source.renpy#fallback-patterns" }
]
Expand Down
44 changes: 23 additions & 21 deletions syntaxes/renpy.tmLanguage.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,12 +253,12 @@
{
"comment": "[TODO: Should probably only be a keyword in the expression] Renpy sub expression keywords",
"name": "keyword.other.renpy",
"match": "\\b(?<!\\.)(?:set|expression|at|with|from|style_prefix|spacing|textbutton)\\b"
"match": "\\b(?<!\\.)(?:set|expression|from|style_prefix|spacing|textbutton)\\b"
},
{
"comment": "[TODO: Should probably only be a keyword in the expression] Renpy sub expression keywords",
"name": "keyword.control.flow.other.renpy",
"match": "\\b(?<!\\.)(?:action)\\b"
"match": "\\b(?<!\\.)(?:action|at|with)\\b"
}
]
},
Expand Down Expand Up @@ -306,25 +306,26 @@
"constant_placeholder": {
"comment": "Python value interpolation using [ ... ]",
"name": "constant.other.placeholder.tags.renpy",
"match": "(\\[)(.*?)(\\])(?![^\\[]*?\\])",
"captures": {
"1": { "name": "constant.character.format.placeholder.other.renpy" },
"2": {
"name": "meta.embedded.line.python",
"patterns": [
{
"name": "meta.interpolate.flags.renpy",
"match": "(!)([rstiqulc]+)",
"captures": {
"1": { "name": "punctuation.definition.interpolate.flags.begin.renpy" },
"2": { "name": "storage.modifier.flag.renpy" }
}
},
{ "include": "source.renpy.python#expression" }
]
"contentName": "meta.embedded.line.python",
"begin": "(?<=[^\\[])\\[",
"end": "\\]",
"beginCaptures": {
"0": { "name": "constant.character.format.placeholder.begin.renpy" }
},
"endCaptures": {
"0": { "name": "constant.character.format.placeholder.end.renpy" }
},
"patterns": [
{
"name": "meta.interpolate.flags.renpy",
"match": "(!)([rstiqulc]+)",
"captures": {
"1": { "name": "punctuation.definition.interpolate.flags.begin.renpy" },
"2": { "name": "storage.modifier.flag.renpy" }
}
},
"3": { "name": "constant.character.format.placeholder.other.renpy" }
}
{ "include": "source.renpy.python#expression" }
]
},
"escaped_unicode_char": {
"match": "(\\\\U[0-9A-Fa-f]{8})|(\\\\u[0-9A-Fa-f]{4})|(\\\\N\\{[a-zA-Z ]+\\})",
Expand Down Expand Up @@ -895,11 +896,12 @@
},
{
"name": "meta.say.narrator.renpy meta.say.statement.renpy",
"begin": "(?<=(^[ \\t]+))(?=r?(?:\"|'|`))",
"begin": "(?<=^[ \\t]+)(?=r?(?:\"|'|`))",
"end": "$",
"patterns": [
{ "include": "#strings" },
{ "include": "source.renpy.python#odd-function-call" },
{ "include": "#with-statement" },
{ "include": "#fallback-patterns" }
]
}
Expand Down
Loading