可以在我的VS代码扩展程序上获取自定义配置点

发布于 2025-02-12 05:31:06 字数 3528 浏览 1 评论 0原文

因此,我花了很多时间试图使几个特定的​​设置在VS代码中用于我的语言扩展,而在线文档和几篇文章似乎使它听起来很简单,就像在中添加一个“配置”点我的poffage.json和“ getConfiguration()”在extension.ts文件中调用,似乎需要更多才能使它们正常工作。这是我制作的第一个扩展程序,所以我对其中一些事情有点不熟悉。

我正在研究这个项目,因此我将在下面的某些编辑中粘贴一些代码。我现在遇到的主要问题是它认识到我已经将配置点添加到了包JSON中,但是在尝试调试扩展程序时,我会遇到此错误:

无法注册'< configuration_name>'。该属性已经注册了

我已经在线阅读了很多有关此属性的信息,似乎问题是VS代码正在将这些设置视为已经定义的,因此很困惑,因为它可能会期望自定义配置。我不知道。我觉得尽管问题必须存在于我的extension.ts文件中,因为当我查看github上的VS代码示例示例上的配置示例时,它们所做的不仅仅是简单的“ getConfiguration()我正在使用的函数” 。但是我真的不知道我会做什么。我对Typescript并不熟悉,因此,对此表示感谢。有人对为什么会这样做有任何见解?

这是我的软件包。JSON:

{
"name": "ex-lang",
"displayName": "Example",
"description": "Example language support",
"version": "0.0.1",
"engines": {
    "vscode": "^1.64.2"
},
"categories": [
    "Programming Languages",
    "Snippets"
],
"contributes": {
    "languages": [
        {
            "id": "ex",
            "aliases": [
                "EX",
                "ex",
                "Example"
            ],
            "extensions": [
                ".ex"
            ],
            "configuration": "./language-configuration.json",
            "icon": {
                "light": "./icons/icon.png",
                "dark": "./icons/icon.png"
            }
        }
    ],
    "grammars": [
        {
            "language": "ex",
            "scopeName": "source.ex",
            "path": "./syntaxes/ex.tmLanguage.json"
        }
    ],
    "snippets": [
        {
            "language": "ex",
            "path": "./snippets.json"
        }
    ],
    "configuration": [
        {
            "id": "ex-config",
            "title": "Example Custom Settings",
            "properties": {
                "editor.tokenColorCustomizations": {
                    "textMateRules": [
                        {
                            "scope": [
                                "comment.block.documentation.ex"
                            ],
                            "settings": {
                                "foreground": "#efc752"
                            }
                        }
                    ]
                },
                "editor.bracketPairColorization.enabled": true,
                "workbench.colorCustomizations": {
                    "editorBracketHighlight.foreground1": "#2b85d5",
                    "editorBracketHighlight.foreground2": "#559ddd",
                    "editorBracketHighlight.foreground3": "#80b6e6",
                    "editorBracketHighlight.foreground4": "#aaceee",
                    "editorBracketHighlight.foreground5": "#d5e7f7",
                    "editorBracketHighlight.foreground6": "#c6cad4",
                    "editorBracketHighlight.unexpectedBracket.foreground": "#db6165"
                }
            }
        }
    ]
},
"dependencies": {
    "vsce": "^2.9.2"
},
"devDependencies": {
    "@types/node": "^16.11.7",
    "@types/vscode": "^1.40.0",
    "@typescript-eslint/eslint-plugin": "^5.19.0",
    "@typescript-eslint/parser": "^5.19.0",
    "eslint": "^8.13.0",
    "typescript": "^4.7.2"
}

}

我尝试过一些激活事件的混乱,但是我遇到了更多问题,因为我想我不像我那样理解它们。我还摆弄了用于配置点的不同范围,但无济于事。最后,我确实有一个“主要”贡献点,但是当我遇到它时,我有非常奇怪的路径问题(它一直在说没有找到该文件),所以我将其删除。不确定这些事情是否也导致我的问题。

这是我的extension.ts文件以供参考:

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

    vscode.workspace.getConfiguration('ex-config');

}

So I've been spending a lot of time trying to get a couple specific settings working for my language extension in VS Code, and while the documentation and the few articles online seem to make it sound as simple as adding a "configuration" point in my package.json and a "getConfiguration()" call in the extension.ts file, it seems that there is more needed to get them working. This is my first extension I've made so I'm a bit unfamiliar with some of these things.

I am working on this project for work, so I will paste some of my code below with certain edits. The main issue I am getting right now is that it recognizes that I have added the configuration points to the package json, but I get this error when trying to debug the extension:

Cannot register '<configuration_name>'. This property is already registered

I have read as much as I can online about this and it seems that maybe the issue is that VS Code is seeing these settings as already defined and therefore is confused because it may be expecting custom configurations. I'm not sure. I feel though the issue must lie in my extension.ts file since when I look at the configuration example on the VS Code Examples repository on Github, they are doing quite a lot more than just the simple "getConfiguration()" function I am using. But I really have no idea what I would do. I am not very familiar with typescript as of yet, so any help would be greatly appreciated on this. Anyone have any insight as to why it would be doing this?

Here is my package.json:

{
"name": "ex-lang",
"displayName": "Example",
"description": "Example language support",
"version": "0.0.1",
"engines": {
    "vscode": "^1.64.2"
},
"categories": [
    "Programming Languages",
    "Snippets"
],
"contributes": {
    "languages": [
        {
            "id": "ex",
            "aliases": [
                "EX",
                "ex",
                "Example"
            ],
            "extensions": [
                ".ex"
            ],
            "configuration": "./language-configuration.json",
            "icon": {
                "light": "./icons/icon.png",
                "dark": "./icons/icon.png"
            }
        }
    ],
    "grammars": [
        {
            "language": "ex",
            "scopeName": "source.ex",
            "path": "./syntaxes/ex.tmLanguage.json"
        }
    ],
    "snippets": [
        {
            "language": "ex",
            "path": "./snippets.json"
        }
    ],
    "configuration": [
        {
            "id": "ex-config",
            "title": "Example Custom Settings",
            "properties": {
                "editor.tokenColorCustomizations": {
                    "textMateRules": [
                        {
                            "scope": [
                                "comment.block.documentation.ex"
                            ],
                            "settings": {
                                "foreground": "#efc752"
                            }
                        }
                    ]
                },
                "editor.bracketPairColorization.enabled": true,
                "workbench.colorCustomizations": {
                    "editorBracketHighlight.foreground1": "#2b85d5",
                    "editorBracketHighlight.foreground2": "#559ddd",
                    "editorBracketHighlight.foreground3": "#80b6e6",
                    "editorBracketHighlight.foreground4": "#aaceee",
                    "editorBracketHighlight.foreground5": "#d5e7f7",
                    "editorBracketHighlight.foreground6": "#c6cad4",
                    "editorBracketHighlight.unexpectedBracket.foreground": "#db6165"
                }
            }
        }
    ]
},
"dependencies": {
    "vsce": "^2.9.2"
},
"devDependencies": {
    "@types/node": "^16.11.7",
    "@types/vscode": "^1.40.0",
    "@typescript-eslint/eslint-plugin": "^5.19.0",
    "@typescript-eslint/parser": "^5.19.0",
    "eslint": "^8.13.0",
    "typescript": "^4.7.2"
}

}

I have tried messing a bit with Activation Events, but I was getting more issues with it as I suppose I don't understand them as well as I might like. I have also fiddled with different scopes for the configuration points and such but to no avail. And lastly, I did have a "main" contribution point, but I was having very strange pathing issues when I had it (it kept saying the file was not found), so I removed it. Not sure if any of these things are also contributing to my problem or not.

Here is my extension.ts file for reference:

import * as vscode from 'vscode';

export function activate(context: vscode.ExtensionContext) {

    vscode.workspace.getConfiguration('ex-config');

}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文