有没有人有建立在Visual Studio中的自定义文本标记的例子吗?自定义、有没有人、标记、例子

2023-09-03 21:12:42 作者:我的温柔喂过狗

在情况下我最初的做法是错误的,这里就是我试图完成。我希望能够识别文本片段在我的code编辑器(我使用C#,但是这不应该的问题),并改变他们被格式化的方式。也许用不同的颜色或字体,等我开始想,这将是作为弹出一个普通的前pression成一个配置文件的地方,并设置一些默认设置为容易...没有这么多。

In case my initial approach is wrong, here's what I'm trying to accomplish. I want to be able to recognize snippets of text in my code editor (I'm using C#, but that shouldn't matter) and change the way they are formatted. Perhaps use different colors or fonts, etc. I started off thinking this would be as easy as popping a regular expression into a config file somewhere and setting some defaults... not so much.

我到目前为止已经确定了两种可能的方法可以做到这一点,首先是为Visual Studio创建一个新的语言服务。我不认为这是有道理的,因为我真的只是充实了默认的C#的lex和放大器;解析。

I've so far identified two potential ways to do this, the first is by creating a new Language Service for Visual Studio. I don't think this makes sense because I'm really only augmenting the default C# lex & parse.

二是通过如何创建自定义文本标记的。这似乎更好,因为如果我正确地读它,这将让我创造我自己的规则,用于识别在IDE中的文本(正则表达式等)的部分,并添加基于文本标记。这些将在随后的选项被曝光 - >环境 - >字体和颜色区在Visual Studio选项(类似于ReSharper的覆盖,ReSharper的死code等)

The second is by How to: Create Custom Text Markers. This seems better, because if I'm reading it correctly this will allow me to create my own rules for recognizing sections of text (regex, etc) in the IDE and add Text Markers based on that. Those will then be exposed in the Options -> Environment -> Fonts and Colors area in Visual Studio Options (similar to ReSharper Overrides, ReSharper DeadCode, etc.).

假设自定义文本标记路线是要走的路,我开到其他的想法,我需要实现的 IVsPackageDefinedTextMarkerType 接口和实施 GetTextMarkerType 方法。听起来pretty的直线前进......

Assuming the Custom Text Markers route is the way to go, and I'm open to other ideas, I need to implement the IVsPackageDefinedTextMarkerType interface and implement the GetTextMarkerType method. Sounds pretty straight forward...

然后我需要在毫无顾忌[我]标记类型即服务,这是我得到一点点失落。有创建在Visual Studio SDK定制服务的例子,但我无法弄清楚如何把两者结合起来。我还有大量的研究要做这个话题,所以我可能会回答我的问题,但它会是很好,如果有人能救我一些时间!

I then need to "proffer [my] marker type as a service", this is where I get a little lost. There is an example of creating a custom service in the Visual Studio SDK, but I can't figure out how to tie the two together. I've still got a lot of research to do on this topic, so I may answer my own question, but it'd be nice if someone could save me some time!

推荐答案

我认为,以下的项目中使用自定义文本标记。他们可能给你一些想法:

I believe that the following projects use custom text markers. They might give you some ideas:

HTTP://snippetdesigner.$c$cplex.com/ HTTP://clonedetectivevs.$c$cplex.com http://snippetdesigner.codeplex.com/ http://clonedetectivevs.codeplex.com