自动缩进不适用于SAS语言扩展

问题描述 投票:1回答:1

我正在尝试将我的SAS语言扩展名从Atom https://atom.io/packages/language-sas移植到VScode。除自动缩进外,其他所有功能(语法等)均正常。

我使用yo code为我的SAS语言扩展创建模板。我尝试使用与Atom中相同的正则表达式,但它们似乎不起作用。我还尝试了一些非常简单的设置,例如"increaseIndentPattern": "^\s*(data|proc)\s*;$,但它们似乎也不起作用。

我当前安装了以下扩展:Python,Remote-SSH,TSLint,Visual Studio Intellicode,Tomorrow颜色主题。

这里是我的package.jsonlanguage-configuration.json

{
    "name": "sas-language",
    "displayName": "SAS",
    "description": "SAS language support for Visual Studio Code",
    "version": "0.0.1",
    "engines": {
        "vscode": "^1.36.0"
    },
    "categories": [
        "Programming Languages"
    ],
    "contributes": {
        "languages": [
            {
                "id": "sas",
                "aliases": [
                    "SAS",
                    "sas"
                ],
                "extensions": [
                    ".sas"
                ],
                "configuration": "./language-configuration.json"
            }
        ],
        "grammars": [
            {
                "language": "sas",
                "scopeName": "source.sas",
                "path": "./syntaxes/language-sas.json"
            }
        ],
        "snippets": [
            {
                "language": "sas",
                "path": "./snippets/language-sas.json"
            }
        ]
    }
}
{
    "comments": {
        "lineComment": "*",
        "blockComment": ["/*", "*/"]
    },
    "brackets": [
        ["{", "}"],
        ["[", "]"],
        ["(", ")"]
    ],
    "autoClosingPairs": [
        {"open": "{", "close": "}"},
        {"open": "[", "close": "]"},
        {"open": "(", "close": ")"},
        {"open": "\"", "close": "\"", "notIn": ["string", "comment"]},
        {"open": "'", "close": "'", "notIn": ["string", "comment"]}
    ],
    "surroundingPairs": [
        ["{", "}"],
        ["[", "]"],
        ["(", ")"],
        ["\"", "\""],
        ["'", "'"]
    ],
    "indentationRules": {
        "increaseIndentPattern": "(?i:(\\bdo\\b(.(?!end;))*$|\\bbegingraph\\b(.(?!endgraph;))*$|^\\s*(proc|data|%macro)\\s+.*;\\s*$))",
        "decreaseIndentPattern": "(?i:(^\\s*(%?end|endgraph|endsas|run|quit|%mend)\\s*;))"
    }
}
visual-studio-code sas indentation vscode-extensions
1个回答
0
投票

找到了以下两个问题的答案:https://github.com/microsoft/vscode/issues/74493https://github.com/microsoft/vscode/issues/27591#issuecomment-305175307

问题出在忽略大小写修饰符(?i:)中。显然,这是未记录的行为。删除(?i:)修饰符,然后用{"pattern": regex_string; flags: "i"}替换regex_string。因此,代替:

"increaseIndentPattern": "(?i)...your regex here..."

写:

"increaseIndentPattern": {"pattern": "(?i)...your regex here...", "flags": "i"}

您的缩进规则变为:

"indentationRules": {
    "increaseIndentPattern": {"pattern": "\\bdo\\b(.(?!end;))*$|\\bbegingraph\\b(.(?!endgraph;))*$|^\\s*(proc|data|%macro)\\s+.*;\\s*$", "flags": "i"},
    "decreaseIndentPattern": {"pattern": "^\\s*(%?end|endgraph|endsas|run|quit|%mend|((proc|data)\\s+.*))\\s*;", "flags": "i"}

}
© www.soinside.com 2019 - 2024. All rights reserved.