locked
Is it possible to call the GetDeclarations method of the XmlLanguageService from my own language service? RRS feed

  • Question

  • I have written a language service for a development language that we use to produce our business logic in. This language looks a lot like XML and in fact we've written an xsd that facilitates using the language in the Visual Studio XmlEditor. However, as soon as I load my language service into Visual Studio, I have to disassociate the file extension (of the business logic file) from the XmlEditor to make my language service work (what it does is to facilitate intellisense that is of a dynamic nature, and therefore cannot be put into an xsd). But of course I would like to be able to use the things the xsd offers as well. I thought the following reasoning would be valid:

    The AuthoringSource.GetDeclarations is offered a list of Declarations that holds for example the attributes for a certain xml-tag.  Perhaps I can fake the XmlLanguageService into giving me those attributes if I offer it the location (row, col) in the text where it would normally produce them. I tried it thus (which, as you certainly guessed, doesn't work):

    public XmlLanguageService GetXmlLanguageService()
    {
    	return (XmlLanguageService)this.GetService(typeof(XmlLanguageService));
    }
    private Declarations GetSomething(IVsTextView vsTextView, int line, int column, TokenInfo info, ParseReason reason)
    {
    	XmlLanguageService xmlLanguageService = wflLanguageService.GetXmlLanguageService();
    	IVsTextLines textLines;
    	vsTextView.GetBuffer(out textLines);
    	Source source = xmlLanguageService.CreateSource(textLines);
     
    	Microsoft.XmlEditor.XmlDocument doc = xmlLanguageService.GetParseTree(
    		source,
    		vsTextView,
    		line,
    		column,
    		reason);
     
    	info.Trigger = TokenTriggers.Parameter;
    	info.Type = TokenType.Keyword;
     
    	AuthoringScope authoringScope = xmlLanguageService.GetAuthoringScope(doc);
     
    	Declarations decls = authoringScope.GetDeclarations(vsTextView, line, column, info, reason);
     
    	return decls;
    }

    My questions are:

    Is there someone who might help me in this?

    Is what I'm trying to do even possible?


     
    Thursday, October 23, 2014 2:53 PM

Answers

  • Hi, Henk.

    That's no way to do what you want to. The reality is so, that VS can have just one Language Service active on file in one time. One of the possible solutions is to manually get the desired structure from your XSD file (like possible nested items and attributes of current item), and do all you want by hand.

    There is another approach for VS 2010+. Don't implement full Language Service, but extend the XML one with MEF editor extension technique (Extending the Editor). I suppose you have a best results than with your replacement approach.

    • Marked as answer by Caillen Monday, November 3, 2014 2:13 AM
    Friday, October 24, 2014 6:51 PM