VS Code:使用自定义词汇表进行自动完成的最佳方式

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

VS Code: Best way to use custom wordlist for autocomplete

问题

我正在使用VS Code编写Markdown文件。是否有办法在自动完成中使用存储在已打开Markdown项目外的单独文件夹中的术语词汇表?目前,所有技术术语的词汇表格式是一个文本文件,每一行都有一个特定的术语。但是,如果需要的话,可以重新格式化此文件。

英文:

I am using VS Code to write markdown files. Is there any way to use a wordlist with technical terms, which is stored in a separate folder outside the opened markdown project, for autocompletion?

At the moment the format of the wordlist with all technical terms is a text file which has on each line a particular term. However, it would be possible to reformat this file if necessary.

答案1

得分: 1

你可以使用扩展 Complete from File

你需要在 settings.json 中定义语言ID和要在配置中使用的文件:

  "complete-from-file.documents": {
    "markdown completions": {
      "documentSelectors": [{ "language": "markdown", "scheme": "file" }],
      "files": [
        "${workspaceFolder}${pathSeparator}markdown-complete.txt",
        "${userHome}${pathSeparator}completions${pathSeparator}markdown-complete.txt"
      ]
    }
  }

文件中的每一行都作为一个可能的完成项。文件可以包含注释(//# 行)和空行。完成行可以包含任何字符(包括空格),但起始字符必须是单词字符。

默认情况下,您至少需要3个字符才能获得完成。此设置可以更改(complete-from-file.minimalCharacterCount)。

在Markdown文件中,您可以使用以下方式请求完成:
触发建议(快捷键:ctrl+space,命令ID:editor.action.triggerSuggest

英文:

You can use the extension Complete from File.

You have to define the languageID and files to use with a configuration in settings.json:

  "complete-from-file.documents": {
    "markdown completions": {
      "documentSelectors": [{ "language": "markdown", "scheme": "file" }],
      "files": [
        "${workspaceFolder}${pathSeparator}markdown-complete.txt",
        "${userHome}${pathSeparator}completions${pathSeparator}markdown-complete.txt"
      ]
    }
  }

Each line of the file is used as a possible completion item. The file can contain comments (// and # lines) and empty lines. A completion line can contain any character (including spaces) but the initial characters must be word characters.

The default is that you need at least 3 characters to get a completion.
This setting can be changed (complete-from-file.minimalCharacterCount).

In Markdown files you have to request a completion with:
Trigger Suggest (key: ctrl+space, commandID: editor.action.triggerSuggest)

答案2

得分: 0

如果您在项目中打开了该词汇表,我认为这个设置应该有所帮助:

编辑器:基于单词的建议模式  // 设置为allDocuments

这应该会建议所有打开文档中的单词。

但您可能还需要在您的 settings.json 中添加以下内容:

"[markdown]": {
  "editor.quickSuggestions": {
    "other": "on",
    "comments": "on",
    "strings": "on"
  }
},

(我不记得为什么现在,但我认为您需要为Markdown文件进行特殊处理。)如果我这样做,我会得到建议完成的建议。

否则,您可能需要使用 CompletionProvider 制作您的扩展,其中包含您的词汇表。

英文:

If you have that wordlist open in your project, I would think that this setting should help:

Editor: Word Based Suggestions Mode  // set to allDocuments

That should suggest words from all open documents.

But you may need this in your settings.json as well:

  "[markdown]": {
    "editor.quickSuggestions": {
      "other": "on",
      "comments": "on",
      "strings": "on"
    }
  },

(I can't recall why just now but I believe you need special handling for markdown files.) I do get completion suggestions if I do this.

Other wise you would probably have to make your extension with a CompletionProvider which incorporates your wordlist.

huangapple
  • 本文由 发表于 2023年5月8日 01:41:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76195394.html
匿名

发表评论

匿名网友

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

确定