在对ParseSource()的调用之间保持持久结果,以及处理从后台线程到文本缓冲区索引的行/列转换? [英] Keeping persistent results between calls to ParseSource(), and dealing with line/col conversion to text buffer index from background thread?

查看:74
本文介绍了在对ParseSource()的调用之间保持持久结果,以及处理从后台线程到文本缓冲区索引的行/列转换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为内部使用的脚本语言编写了一个有效的语言服务,但是随着我逐步了解所有事情,我现在回头看看它并添加更多功能和改进,我我意识到我已经做了很多事情 有潜在危险.

I've written a working Language Service for the scripting language we use internally, but as I was figuring everything out as I went along I'm now looking back at it and adding more features and improvements and I've realized I've done a number of things that are potentially dangerous.

首先,我将解析的结果(方法,类型等)存储在自定义AuthoringScope子类中.我将AuthoringScope对象保存在Source对象内,该对象与ParseRequest请求的文件相对应.尽管 这可能并不可怕,文档明确指出只能从UI线程访问Source对象.由于ParseSource()是在后台线程上调用的,因此我已经对其进行了更改,以便AuthoringScope由解析产生 由LanguageService自己跟踪.

First off, I've been storing the results (methods, types, etc) of my parses inside my custom AuthoringScope subclass. I was saving the AuthoringScope object inside of the Source object that corresponded to the file that the ParseRequest requested. While this probably isn't terrible, the documentation makes it pretty clear that Source objects must only be accessed from the UI thread. Since ParseSource() is called on a background thread, I've since changed it so that the AuthoringScope results from the parse are kept track of by the LanguageService itself.

这是跟踪ParseReason.Check请求结果的好方法吗?当前,每当我收到这些请求之一时,我都会转储以前的结果并再次解析整个文件.我确实跟踪上一次完全成功的解析,并且 如果当前解析失败,请合并我可以的.我以这种方式保存它们,以便以后进行ParseSource()调用时,我可以立即访问已解析的数据,并且可以在AuthoringScope对象上设置一些字段,这些字段将用于返回 一旦ParseSource()完成,就可以纠正数据.

Is this a good way of keeping track of the results of a ParseReason.Check request? Currently, whenever I receive one of those requests I'm dumping my previous results and parsing the entire file again. I do keep track of the last fully successful parse and merge what I can if the current parse fails. I'm saving them off this way so that when later ParseSource() calls come through I've got immediate access to the parsed data and I can set some fields on my AuthoringScope object that will be used to return the correct data once ParseSource() completes.

现在到问题的第二部分:在我的某些ParseSource()代码中,例如,当我匹配括号时,以及在对ParseRequest的文本进行标记化之后,尝试确定在ParseRequest的行和列之前是什么文本时缓冲我 使用IVsTextLines进行操作,例如将行和列的值转换为文本缓冲区中的位置索引,并简化获取行和其他信息的长度.我意识到这非常非常糟糕,因为我搞砸了 文档中多次提到的对象不应从非UI线程触及.我是否可以将文本缓冲区放入另一个对象中,从而使我能够方便地访问该信息?还是在这种情况下我将不得不 滚动我自己的代码进行此类转换并查询我要查找的数据?

And now to the second part of the question: In some of my ParseSource() code, for example when I'm matching braces and when trying to determine what text is before the ParseRequest's line and column, after tokenizing the ParseRequest's text buffer I'm then using the IVsTextLines in order to do things like convert line and column values into a position index into the text buffer, and to simplify getting the lengths of lines and other information. I realize this is very, very bad since I'm messing with an object that the documentation mentions multiple times should NOT be touched from a non-UI thread. Is there another object I can feed the text buffer into that will give me the same convenient access to that information? Or in this case am I going to have to roll my own code to do such conversions and query the data I'm looking for?

对于它的价值,我还在AuthoringScope的方法中使用了许多IVsTextLines功能,但是我可以肯定,这些方法是从UI线程中调用的,我的用法应该是安全的.

For what it's worth, I also use a lot of the IVsTextLines functionality inside my AuthoringScope's methods, but I'm fairly certain those methods are being called from the UI thread and my usage there should be safe.

在此先感谢您提供任何想法!我有一种感觉,我可以更改代码中标记输入文本的代码,以使它可以将开始索引和结束索引都计算到文本缓冲区中,并且可以在扫描该范围时创建一个TextSpan. 输入文字,并在我进行操作时跟踪这些数据.如果我走那条路线,那么我也应该能够缓存行长,这样我就可以做目前使用IVsTextLines的大部分工作.只是感觉应该仍然有一种方法可以利用IVsTextLines

Thanks in advance for any ideas! I have a feeling that I may be able to change the code that tokenizes the input text to have it calculate both start and end indices into the text buffer as well as creating a TextSpan for that range if I scan through the text and keep track of that data as I go along. If I go that route, I should also be able to cache line lengths and such to allow me to do much of what I'm currently using IVsTextLines for now. It just feels like there ought to be a way to still utilize IVsTextLines' functionality without having to rewrite it all by hand, though...

推荐答案

嗨迪伦,

我对语言服务不熟悉.您可以在msdn库中查看引用:

I am not familiar with the Language Service. You can view the reference in the msdn library:

http://msdn.microsoft.com/en-us/library/bb165662(v = vs.110).aspx

我将邀请一些专家来研究这个问题,以了解他们是否可以在圣诞节假期之后为您提供帮助.可能会有一些时间延迟,感谢您的耐心配合.
 
感谢您的理解和支持.
 
最好的问候,

I will involve some experts into this issue to see whether they can help you out after the Christmas holiday. There might be some time delay, appreciate for your patience.
 
Thank you for your understanding and support.
 
Best regards,


这篇关于在对ParseSource()的调用之间保持持久结果,以及处理从后台线程到文本缓冲区索引的行/列转换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆