VSCode项目片段在Windows上无法按预期工作

huangapple go评论52阅读模式
英文:

VSCode project snippets not working as expected on Windows

问题

我开始输入前缀"conso",我希望代码片段建议会显示在顶部。实际上,在MacOS上工作正常。然而,在Windows上没有显示任何代码片段建议。

.vscode/snippets/typescript.json

{
   "console": {
     "prefix": "console",
     "body": "console.log('$1', $1);$2"
   }
}

.vscode/settings.json

{
"editor.tabCompletion": "on",
"editor.snippetSuggestions": "top",
}

Visual Code中安装的扩展

"rebornix.project-snippets"

我尝试重新启动Visual Studio Code甚至重新加载窗口,但问题仍然存在。似乎代码片段本身没有正确触发。

英文:

I start typing the prefix "conso" and I would expect that the snippets suggestions will show at the top. In fact, it is working on MacOS. However, on Windows no snippet suggestions are shown.

.vscode/snippets/typescript.json

{
   "console": {
     "prefix": "console",
     "body": "console.log('$1', $1);$2"
   }
}

.vscode/settings.json

{ 
  "editor.tabCompletion": "on",
  "editor.snippetSuggestions": "top",
}

Extension Installed in Visual Code

    "rebornix.project-snippets"

I've tried restarting Visual Studio Code and even reloading the window, but the problem persists. It seems like the snippet itself is not being triggered properly.

答案1

得分: 2

I see you have your typescript.json snippets file in this location:

.vscode/snippets/typescript.json

It does not go there - the snippets folder is just for emmet snippets (and they have a very different form).

When you go to the Gear icon (lower left) and open User Snippets and choose your language, vscode will create the file in the proper location. Then you can open that - by going to the same Gear/User Snippets - look for your your <language>.json file listed there and insert your snippet into that.

If you choose to create a snippets file for that particualr workspace, the snippets file would be located at

.vscode/<aNameYouChoose>.code-snippets

and your snippet would go into that file.

With the additional info that you were trying to get the Project Snippets extension to work, I had to go to its repository to see that it is deprecated:

🚨 Deprecated 🚨 - This feature is now part of VSCode
This feature now ships with visual studio code!

Steps to using built-in workspace snippets:

Create a {namehere}.code-snippets file in .vscode folder The file must
be within .vscode folder (not in sub-folders) Your snippets can now be
checked in and shared with your team Note: when using the snippet you
will see (Workspace Snippet) in the intellisense autocomplete
dropdown.

It is very unfortunate that he hasn't published the README info to the Marketplace version of the extension!

In any case, if you create a <aNameYouChoose>.code-snippets file in the .vscode folder that is where you put your snippets. It really doesn't matter what you name it as you cannot limit their scope by the fileName, but you can in each snippet itself with the scope argument:

{

  "console": {
    "prefix": "console",
    "scope": "typescript",
    "body": "console.log('$1', $1);$2"
  }
}
英文:

I see you have your typescript.json snippets file in this location:

.vscode/snippets/typescript.json

It does not go there - the snippets folder is just for emmet snippets (and they have a very different form).

When you go to the Gear icon (lower left) and open User Snippets and choose your language, vscode will create the file in the proper location. Then you can open that - by going to the same Gear/User Snippets - look for your your <language>.json file listed there and insert your snippet into that.

If you choose to create a snippets file for that particualr workspace, the snippets file would be located at

.vscode/&lt;aNameYouChoose&gt;.code-snippets

and your snippet would go into that file.


With the additional info that you were trying to get the Project Snippets extension to work, I had to go to its repository to see that it is deprecated:

> 🚨 Deprecated 🚨 - This feature is now part of VSCode
> This feature now ships with visual studio code!
>
> Steps to using built-in workspace snippets:
>
> Create a {namehere}.code-snippets file in .vscode folder The file must
> be within .vscode folder (not in sub-folders) Your snippets can now be
> checked in and shared with your team Note: when using the snippet you
> will see (Workspace Snippet) in the intellisense autocomplete
> dropdown.

It is very unfortunate that he hasn't published the README info to the Marketplace version of the extension!

In any case, if you create a &lt;aNameYouChoose&gt;.code-snippets file in the .vscode folder that is where you put your snippets. It really doesn't matter what you name it as you cannot limit their scope by the fileName, but you can in each snippet itself with the `scope argument:

{

  &quot;console&quot;: {
    &quot;prefix&quot;: &quot;console&quot;,
    &quot;scope&quot;: &quot;typescript&quot;,
    &quot;body&quot;: &quot;console.log(&#39;$1&#39;, $1);$2&quot;
  }
}

huangapple
  • 本文由 发表于 2023年7月28日 00:45:53
  • 转载请务必保留本文链接:https://go.coder-hub.com/76781878.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定