带有 C# 智能感知的 Visual Studio 语言服务

发布于 2024-07-17 08:04:12 字数 452 浏览 10 评论 0原文

去年,我为 Visual Studio 编写了一个语言服务,为 NHaml 文件添加了语法突出显示: http://github.com/snappycode /hamleditor

澄清一下,NHaml 是一种 html 模板语言,可以像 aspx 文件一样混合代码元素。 该插件添加了对 IDE 编辑 NHaml 文件的支持,但基本上仅添加语法突出显示。

我想知道是否有人知道如何将内联 c# 智能感知添加到服务中,就像现在在 aspx 文件中一样。 我希望这将是可能的,而无需自己专门针对该插件执行整个 C# 语法。

有人编写过混合语言的语言服务吗?

更新: 看起来 Spark View 引擎的家伙已经在这里取得了一些进展,我正在调查他们的实施

Last year I wrote a Language Service for Visual Studio which added syntax highlighting for NHaml files: http://github.com/snappycode/hamleditor.

To clarify, NHaml is a html template language that can mix in code elements like an aspx file can. This plugin adds support to the IDE for editing NHaml files, but basically only adds syntax highlighting.

I was wondering if anyone knows how to add inline c# intellisense to the service like you get now in an aspx file. I'm hoping that would be possible without doing the whole c# grammar myself specific for the plugin.

Has anyone written a language service that mixes languages?

UPDATE:
It looks like the spark view engine guys have made some inroads here, I am investigating their implementation

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你的笑 2024-07-24 08:04:12

我检查了 Spark View Engine,他们似乎制作了一个通用的 ATL 东西(称为 SparkLanguagePackageLib),实际上似乎不包含 Spark 特定的任何内容。 它似乎只是一个通用的 C# 智能感知库,需要以下内容:

  • 原始代码
  • 从原始代码生成的 C# 源
  • 两者之间的位置映射(例如第 2 行 pos 5 上的代码在输出中映射到第 4 行 pos 10 等)
  • 一些其他的东西,比如画(?)

之后你可以调用:

events.OnGenerated(
    primaryText, // original source code
    entry.SourceCode, // generated sourcecode
    cMappings, // mappings between the two
    ref mappings[0], // ?
    cPaints, // ?
    ref paints[0]); // ?

我试图在那个 C++ 库中找到 Spark 特定的东西,但我找不到任何东西:everythig spark-相关的被拆分为单独的 C# 代码文件。 我认为这很好,因为:

  • 你不需要编辑 C++ 文件
  • 如果安装了 Spark 视图引擎的智能感知支持,它也可以被其他视图引擎使用
  • 你只需要创建一个类,它在原始 nhaml 之间映射文件及其生成的 C# 对应项。

顺便提一句。 您还在研究这个 NHaml Intellisense 库吗? 如果没有,我会尝试修补他们的实现,希望它可以轻松转换为 NHaml。

I checked the Spark View Engine, and they seem to have made a generic ATL stuff (called SparkLanguagePackageLib), that in fact seems to be not containiag anything Spark specific. It seems to be just a generic C# intellisense library that needs the following:

  • The original code
  • The C# source that gets generated from the original code
  • The position mappings between the two (for example the code on line 2 pos 5 gets mapped in the output to line 4 pos 10, etc.)
  • Some other things, like Paintings(?)

And after that you can call:

events.OnGenerated(
    primaryText, // original source code
    entry.SourceCode, // generated sourcecode
    cMappings, // mappings between the two
    ref mappings[0], // ?
    cPaints, // ?
    ref paints[0]); // ?

I've tried to find Spark-specific stuff in that C++ library, but I couldn't find anything: everythig spark-related is split to a separate C# code file. I think this is good, because:

  • You don't need to edit the C++ files
  • If the spark view engine's intellisense support is installed it can be used by other view engines too
  • You only need to create a class, that maps between the original nhaml file and it's generated C# counterpart.

Btw. Are you still working on this NHaml Intellisense library? If not I'll try to patch their implementation in hope it can be converted to NHaml easily.

过气美图社 2024-07-24 08:04:12

我最终设法修改代码以支持 NHaml。 一点也不难。 不幸的是,原始的 NHaml 库并不支持所需的一切,因此我必须为 NHaml 创建一个新的解析器。 它不支持所有结构,但它支持大多数结构(足以使 NHaml 编程更容易)

下载: http://github.com/sztupy/nhamlsense

截屏:http://www .youtube.com/watch?v=8jTZ2zC9eYc

I finally managed to modify the code to support NHaml. It wasn't that hard at all. Unfortunately the original NHaml library doesn't support everything that was needed, so I had to create a new parser for NHaml. It doesn't support all of the constructs, but it supports most of them (enough to make NHaml programming easier)

Download: http://github.com/sztupy/nhamlsense

Screencast: http://www.youtube.com/watch?v=8jTZ2zC9eYc

花落人断肠 2024-07-24 08:04:12

您可以通过创建或修改来轻松添加关键字 usertype.dat 文件。 请查看此处,了解有关附加到的一些说明特定的文件扩展名。 这可能至少能让您完成部分工作,而无需重做完整的 C# 语法。

(事实上​​,我不确定在这种情况下“语法突出显示”的确切含义。例如,我确信您可以在编辑器中免费获得大括号匹配突出显示)。

You can easily add keywords by creating or modifying a usertype.dat file. Check here for some directions on attaching to specific file extentions. That might get you at least part of the way, without redoing the complete c# syntax.

(In fact, I'm not sure what you mean exactly by 'syntax highlighting' in this context. I'm sure, for instance, you get brace-match highlighting for free in the editor).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文