使用Visual Studio 2022。我正在尝试编写自己的语言扩展,它可以为我的工作使用的自定义语言自动完成。我试过遵循文档,视频和聊天gpt,但不能让自动完成工作,甚至不能加载我的代码上的符号。我创建了一个类来定义扩展和内容类型
using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualStudio.Utilities;
namespace OpcenterCoreLanguagePlugin.Types
{
public class FileAndContentTypeDefinitions
{
[Export]
[Name("CommonLanguageFunction")]
[BaseDefinition("text")]
internal static ContentTypeDefinition CommonLanguageFunctionDefinition;
[Export]
[ContentType("CommonLanguageFunction")]
[FileExtension(".clf")]
internal static FileExtensionToContentTypeDefinition CommonLanguageFunctionTypeDefinition;
}
}
然后我使用以下代码创建了一个源提供程序:
[Export(typeof(ICompletionSourceProvider))]
[ContentType("CommonLanguageFunction")]
[Name("CLFAutoComplete")]
和完成处理程序
[Export(typeof(IVsTextViewCreationListener))]
[Name("CLFcompletionhandler")]
[ContentType("CommonLanguageFunction")]
[TextViewRole(PredefinedTextViewRoles.Editable)]
我的问题是,这些符号似乎甚至没有加载这些类的实际代码。我没有包含代码,因为我认为它不一定相关。我只是想在我开始写实际的逻辑之前得到一个要显示的静态字符串列表。
是否有我遗漏的其他步骤?我好像找不到别的事可以做了。
我在我的项目中实现了以下接口:
IOleCommandTarget
IVsTextViewCreationListener
ICompletionSource
ICompletionSourceProvider
我在很大程度上复制了Visual Studio说明中的代码https://learn.microsoft.com/en-us/visualstudio/extensibility/walkthrough-displaying-statement-completion?view=vs-2022&tabs=csharp#create-a-mef-project。
只是想在我把他们的代码去掉换成我自己的代码之前看看能不能让它工作。
我试图为自定义文件类型.clf
创建自己的编辑器,并在键入字母时自动完成。
1条答案
按热度按时间lmvvr0a81#
结果是,我必须在vsix文件中将项目标记为MEF组件,以便读取类。花了很长时间才找到这些信息。