VS 2010, IVsTextView.GetWordExtent returning wrong word when looking for previous word RRS feed

  • Question

  • Hi,

    I am using the GetWordExtent method of the IVsTextView interface to locate the previous word in the text buffer for some intellisence operations, however i am finding that the outputed wordextent is two words back and not the previous.

    So with a text buffer of "property Enabled = " GetWordExtent is returning extent for the "property" word and not the expected "Enabled" word. The line and col number are correct when calling GetWordExtent and the word extent flag is WORDEXTFLAGS.WORDEXT_PREVIOUS. This method call worked in VS 2008 and to an extent works in VS 2010 (Call made on text buffer of "property " will return "property" as previous word extent). 

    Any ideas of what might be going on here?

    Thanks in advance,




    Monday, May 31, 2010 4:34 PM

All replies

  • Hi, Kev

    I have tried to reproduce this, but GetWordExtent method works OK on both VS2008 and VS2010. I saw you use the following sentence.

    property Enabled = " GetWordExtent

    What is the line number and column number you use in GetWordExtend? Is the line and column in Enabled or in the “=”?

    Could you give some infor for us to reproduce this ?



    Tuesday, June 1, 2010 9:26 AM
  • Hi Chao,

    The line and column seem to be correct so with the example of "property Enabled ="the line matches the value from the VS editor and the col is 16 which is the position of the cursor directly after the =, and matches the Ch value from the eidtor.  

    The following call is then made in the next parse triggered by the user entering a space 

    view.GetWordExtent(line, col - 1, (uint)wordPosition, wordExtents)

    1 is subtracted from the the col as using the col value returns an error code of 1. The wordPosition value is the WORDEXT_PREVIOUS flag. The view object is of type VsTextViewAdapter.




    Tuesday, June 1, 2010 10:51 AM
  • Played around with this for a while and using reflector figured out that when GetWordExtent is called on VsTextViewAdapter object, it has a ViewFilter member variable, that when not null, GetWordExtent is called on the ViewFilter object and its result is returned. Through having a class that already inheritated from ViewFilter, I was able to override the GetWordExtent method and see that it was the base call to ViewFilters GetWordExtent that is getting the incorrect word. I put a hack into return error code 1 from my overriden version of GetWordExtent and so the VsTextViewAdapter GetWordExtent is running through completly and finding the correct word.

    I guess now I need to find why the ViewFilter object is returning the wrong word.  


    Tuesday, June 1, 2010 4:55 PM
  • Hello, Kev

    Does you issue resolved? If so, could you post your solution here, this will help others in this forum.



    Thursday, June 3, 2010 6:48 AM