12 comments

Alexander,

for any file call
PsiManager.GetInstance(solution).GetPsiFile( projectFile ) or
PsiManager.GetInstance(solution).GetPsiFile( document )

But, the main problem with all website files is that we create PSI
corresponding to C# (or VB) code, that reflects authentic file to some
extent.

--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

But, the main problem with all website files is that we create PSI
corresponding to C# (or VB) code, that reflects authentic file to some
extent.


I known about this problem. I need to get XML PSI for web.config file, but
PsiManager.GetPsiFile returns PSI for the backend code.
I tried to create XML PSI by XmlTreeBuilder, but i can't edit this PSI by
the XmlTagContainerUtil.
How can i get valid XML PSI?

--
Best regards,
Alexander Nesterenko
www.safedevelop.com


0

Alexander,

I known about this problem. I need to get XML PSI for web.config file, but
PsiManager.GetPsiFile returns PSI for the backend code.
I tried to create XML PSI by XmlTreeBuilder, but i can't edit this PSI by
the XmlTagContainerUtil.
How can i get valid XML PSI?


No way in 3.x for it does not exist at all. ReSharper 4.0 builds XML PSI for
web.configs, but not for .resx files.
The only thing possible if you want to use XmlTagContainerUtil is to create
the PSI on demand, modify it, and then perform textual replacement in the
original file.
--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

Hello Sergey,

No way in 3.x for it does not exist at all. ReSharper 4.0 builds XML PSI for
web.configs, but not for .resx files.


will it be possible in 4.0 to use XML PSI in a plugin for files that
match a pattern (say *.hbm.xml)?


Regards,
Stefan Lieser
--
http://www.lieser-online.de

0

Stefan,

will it be possible in 4.0 to use XML PSI in a plugin for files that match
a pattern (say *.hbm.xml)?


What exactly do you need? Currently, if VS opens an XML editor for the file,
then XML psi is built for it. If you want ReSharper to build your custom PSI
for some types of files, there is a possibility for that.

--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

Sergey,

No way in 3.x for it does not exist at all.


It's bad.

ReSharper 4.0 builds XML PSI for web.configs, but not for .resx files.
The only thing possible if you want to use XmlTagContainerUtil is to create
the PSI on demand, modify it, and then perform textual replacement in
the original file.


Can you give more information how to do it?

--
Best regards,
Alexander Nesterenko
www.safedevelop.com


0

Sergey,

I will (again...) try to write an NHibernate plugin. So I need to parse
the *.hbm.xml mapping files to get classnames, propertynames, etc. and
match them with the corresponding elements in C# files.

The first thing I like to implement ist rename support. If you rename a
property that is mapped in a .hbm.xml file this rename should be
reflected there (and vice versa).


Regards,
Stefan Lieser


Sergey V. Coox (JetBrains) schrieb:

Stefan,

>> will it be possible in 4.0 to use XML PSI in a plugin for files that match
>> a pattern (say *.hbm.xml)?


What exactly do you need? Currently, if VS opens an XML editor for the file,
then XML psi is built for it. If you want ReSharper to build your custom PSI
for some types of files, there is a possibility for that.

0

Stefan,

Well, you'll need to implement your own PSI (inherited from XML PSI)for the
*.him.xml files. This will include LanguageService and
ProjectFileLanguageService like it is done in 4.0 for web.config files. Wait
a bit, EAP will start shortly, at that moment the API will be settled down.

--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

Alexander,

>> ReSharper 4.0 builds XML PSI for web.configs, but not for .resx files.
>> The only thing possible if you want to use XmlTagContainerUtil is to
>> create
>> the PSI on demand, modify it, and then perform textual replacement in
>> the original file.
>

Can you give more information how to do it?


I would try the following:
1) Run XmlTreeBuilder for the file text to build psi.
2) Modify that psi
3) Find the tag, that contains the changes, and do the following

TextRange oldRange = oldTag.GetTreeTextRange();
document.ReplaceText( oldRange,newTag.GetText() );

--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Alexander Nesterenko" <alexn@safedevelop.com> wrote in message
news:57490f09228308ca20f3d936119d@news.jetbrains.com...

Sergey,

>
>> No way in 3.x for it does not exist at all.
>

It's bad.

>
>

--
Best regards,
Alexander Nesterenko
www.safedevelop.com

>



0

Hi Sergey,

thanks for the infos. Looking forward to 4.0 EAP...

Regards,
Stefan Lieser

Sergey V. Coox (JetBrains) schrieb:

Stefan,

Well, you'll need to implement your own PSI (inherited from XML PSI)for the
*.him.xml files. This will include LanguageService and
ProjectFileLanguageService like it is done in 4.0 for web.config files. Wait
a bit, EAP will start shortly, at that moment the API will be settled down.

0

Hi Sergey,

I would try the following:
1) Run XmlTreeBuilder for the file text to build psi.
2) Modify that psi
3) Find the tag, that contains the changes, and do the following
TextRange oldRange = oldTag.GetTreeTextRange();
document.ReplaceText( oldRange,newTag.GetText() );


I was looking for method like the PsiManager.GetPsiFile(document, PsiLanguageType).
Thank you for this information but when i use XmlTagContainerUtil:

 0)
{
     IXmlTag rootTag = xmlFile.InnerTags[0];
     using (GlobalIntelliSenseSettings.Instance.CreateDisableAutoFormatCookie())
     using (ModificationCookie cookie = psiFile.ParsedDocument.EnsureWritable())
     {
        if (cookie.EnsureWritableResult != EnsureWritableResult.FAILURE)
        {
           foreach (XmlNode dataNode in GetDataNodes())
           {
              IXmlTag tag = XmlElementFactory.CreateTag(GetNodeXml(dataNode), 
elementFactory);

              if (rootTag.InnerTags.Count > 0)
                 XmlTagContainerUtil.AddTagAfter(rootTag, tag, rootTag.InnerTags[rootTag.InnerTags.Count 
- 1]); /*Exception accured here*/
              else
                 XmlTagContainerUtil.AddTagAfter(rootTag, tag, null);
            }
         }
     }
}
]]>


i get following exception:


--
Best regards,
Alexander Nesterenko
www.safedevelop.com


0

Alexander,

My fault, I completely forgot about that. In order to get it working you
need to place the newly parsed tag under the dummy holder

 PsiManager psiManager = 
> PsiManager.GetInstance(resourceFile.ProjectFile.GetSolution());
>
> XmlElementFactory elementFactory = new 
> XmlElementFactory(XmlLanguageService.XML);
> XmlTreeBuilder treeBuilder = new XmlTreeBuilder(factory, null, 
> XmlLanguageService.XML);
> IXmlFile xmlFile = treeBuilder.BuildXml(resourceFile.ProjectFile);
>
> if (xmlFile != null && xmlFile.InnerTags.Count > 0)
> {
>     IXmlTag rootTag = xmlFile.InnerTags[0];
>>>>>> here
        DummyHolder.CreateDummyHolderFor( rootTag.ToTreeNode(),psiManager );

>>>>>>

>     using 
> (GlobalIntelliSenseSettings.Instance.CreateDisableAutoFormatCookie())
>     using (ModificationCookie cookie = 
> psiFile.ParsedDocument.EnsureWritable())
>     {
>        if (cookie.EnsureWritableResult != EnsureWritableResult.FAILURE)
>        {
>           foreach (XmlNode dataNode in GetDataNodes())
>           {
>              IXmlTag tag = 
> XmlElementFactory.CreateTag(GetNodeXml(dataNode), elementFactory);
>
>              if (rootTag.InnerTags.Count > 0)
>                 XmlTagContainerUtil.AddTagAfter(rootTag, tag, 
> rootTag.InnerTags[rootTag.InnerTags.Count - 1]); /*Exception accured 
> here*/
>              else
>                 XmlTagContainerUtil.AddTagAfter(rootTag, tag, null);
>            }
>         }
>     }
> }
> ]]>


--
Sergey V. Coox
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"


0

Please sign in to leave a comment.