【问题标题】:Auto-indentation not working for SAS language extension自动缩进不适用于 SAS 语言扩展
【发布时间】:2019-07-17 14:41:15
【问题描述】:

我正在尝试将 Atom https://atom.io/packages/language-sas 的 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】:

在这两个问题中找到了您问题的答案:https://github.com/microsoft/vscode/issues/74493 & https://github.com/microsoft/vscode/issues/27591#issuecomment-305175307

问题在于忽略大小写修饰符(?i:)。显然,这是一种无证行为。删除 (?i:) 修饰符,并将 regex_string 替换为 {"pattern": regex_string; flags: "i"}。所以而不是:

"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"}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-10
    相关资源
    最近更新 更多