Problem with LanguageService, DaemonStage and Psi

Hi,

I implemented the ProjectFileLanguageService und LanguageService classes
shown below. Now I have the problem that I get no PSI file in the
DaemonStage becaus PsiManager.PsiFile(m_DaemonProcess.ProjectFile)
returns always null. Please help! If I may send you more infos please
tell me!

Regards,
Stefan Lieser


]]>
//----


DaemonStage -


using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.Shell.Progress;
using JetBrains.Util;

namespace NHibernatePlugin.Analysis.MappingFile
{
public class XmlAnalysisDaemonStageProcess : IDaemonStageProcess
{
private readonly IDaemonProcess m_DaemonProcess;

public XmlAnalysisDaemonStageProcess(IDaemonProcess
daemonProcess) {
m_DaemonProcess = daemonProcess;
}

public DaemonStageProcessResult Execute() {
Logger.LogMessage("NHibernatePlugin:
XmlAnalysisDaemonStageProcess.Execute called");
// Creating container to put highlightings to
DaemonStageProcessResult result = new
DaemonStageProcessResult();

// Getting PSI (AST) for the file being highlighted
IFile file = PsiManager.PsiFile(m_DaemonProcess.ProjectFile);
//********************************************
// file is always null
//********************************************

if (file == null) {
Logger.LogMessage(" NO PSI FILE !!! {0}",
m_DaemonProcess.ProjectFile.Name);
return result;
}

// Running visitor against the PSI
XmlAnalysisElementProcessor elementProcessor = new
XmlAnalysisElementProcessor(m_DaemonProcess);
file.ProcessDescendants(elementProcessor);

// Checking if the daemon is interrupted by user activity
if (m_DaemonProcess.InterruptFlag) {
throw new ProcessCancelledException();
}

// Fill in the result
result.FullyRehighlighted = true;
result.Highlightings =
elementProcessor.Highlightings.ToArray();

return result;
}
}
}

//----


ProjectFileLanguageService -


using System.Collections.Generic;
using System.Drawing;
using JetBrains.ComponentModel;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.ExtensionsAPI.Caches2;
using JetBrains.ReSharper.Psi.Parsing;
using JetBrains.ReSharper.Psi.Xml;
using JetBrains.ReSharper.Psi.Xml.Impl;
using JetBrains.Shell;
using JetBrains.Util;
using NHibernatePlugin.LanguageService;

namespace NHibernatePlugin.LanguageService
{
[ProjectFileLanguageService(new string[] { ".xml" }),
ShellComponentInterface(ProgramConfigurations.ALL),
ShellComponentImplementation, XmlLanguage]
public class MappingFileProjectFileLanguageService :
IDerivedProjectFileLanguageService, IShellComponent
{
public static ProjectFileType MAPPING_FILE = new
ProjectFileType("MappingFile");
private static readonly PsiLanguageType[]
POSSIBLE_PSI_LANGUAGE_TYPES = new PsiLanguageType[] {
MappingFileLanguageService.MAPPING_FILE };
private readonly IWordIndexLanguageProvider
m_WordIndexLanguageProvider = new XmlWordIndexLanguageProvider();

public ProjectFileType GetProjectFileType(IProjectFile file) {

Logger.LogMessage("MappingFileProjectFileLanguageService.GetProjectFileType
for file {0}", file.Name);
if (file.Name.EndsWith(".hbm.xml")) {
Logger.LogMessage(" Mapping File");
return MAPPING_FILE;
}
Logger.LogMessage(" UNKNOWN");
return ProjectFileType.UNKNOWN;
}

public PsiLanguageType GetPsiLanguageType(IProjectFile file) {

Logger.LogMessage("MappingFileProjectFileLanguageService.GetPsiLanguageType
for file {0}", file.Name);
return GetPsiLanguageType(file.LanguageType);
}

public PsiLanguageType GetPsiLanguageType(ProjectFileType
projectFileType) {

Logger.LogMessage("MappingFileProjectFileLanguageService.GetPsiLanguageType
for project file type {0}", projectFileType.Name);
if (projectFileType != MAPPING_FILE) {
Logger.LogMessage(" UNKNOWN");
return PsiLanguageType.UNKNOWN;
}
Logger.LogMessage(" Mapping File");
return MappingFileLanguageService.MAPPING_FILE;
}

public ILexerFactory CreateLexer(ProjectFileType languageType,
IBuffer buffer) {

Logger.LogMessage("MappingFileProjectFileLanguageService.CreateLexer for
language type {0}", languageType.Name);
if (languageType == MAPPING_FILE) {
Logger.LogMessage(" Mapping File");
return new
XmlLexerFactory(MappingFileLanguageService.MAPPING_FILE);
}
Logger.LogMessage(" UNKNOWN");
return null;
}

public ProjectFileType LanguageType {
get { return MAPPING_FILE; }
}

public Image Icon {
get { return null; }
}

public ICollection]]> PossiblePsiLanguageTypes {
get {

Logger.LogMessage("MappingFileProjectFileLanguageService.PossiblePsiLanguageTypes");
return POSSIBLE_PSI_LANGUAGE_TYPES;
}
}

public IWordIndexLanguageProvider WordIndexLanguageProvider {
get {

Logger.LogMessage("MappingFileProjectFileLanguageService.WordIndexLanguageProvider");
// return
ProjectFileLanguageServiceManager.Instance.GetService(XmlProjectFileLanguageService.XML).WordIndexLanguageProvider;
return m_WordIndexLanguageProvider;
}
}

public void Init() {
}

public void Dispose() {
}
}
}


//----


LanguageService -



using JetBrains.ComponentModel;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.ExtensionsAPI.Caches2;
using JetBrains.ReSharper.Psi.Parsing;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.Psi.Xml;
using JetBrains.Shell;
using JetBrains.Util;

namespace NHibernatePlugin.LanguageService
{
[LanguageService,
ShellComponentInterface(ProgramConfigurations.ALL),
ShellComponentImplementation]
public class MappingFileLanguageService : XmlLanguageServiceBase,
IShellComponent
{
public static PsiLanguageType MAPPING_FILE = new
PsiLanguageType("MappingFile");
public const string MAPPING_FILE_LANGUAGEID = "MappingFile";

public MappingFileLanguageService()
: base(MAPPING_FILE) {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService ctor");
}

public override bool ShouldInvalidatePsiCache(IElement element,
PsiChangedElementType elementType) {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.ShouldInvalidatePsiCache called");
return true;
}

public override IParser CreateParser(ILexer lexer, ISolution
solution, IProject project, CheckForInterrupt checkForInterrupt) {
Logger.LogMessage("NHibernatePlugin: CreateParser for
project {0}, language ", project.Name, project.LanguageType.Name);
return new XmlParser(lexer, checkForInterrupt);
}

public override ILanguageCacheProvider CacheProvider {
get {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.CacheProvider called");
return new MappingFileLanguageCacheProvider(MAPPING_FILE);
}
}

public override ITypePresenter TypePresenter {
get {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.TypePresenter called");
return MappingFileTypePresenter.Instance;
}
}

public override PsiLanguageType LanguageType {
get {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.LanguageType called");
return MAPPING_FILE;
}
}

public static MappingFileLanguageService Instance {
get {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.Instance called");
return
Shell.Instance.GetComponent(); } } public void Init() { } public void Dispose() { } } } ]]>

2 comments
Comment actions Permalink

Looks like ReSharper thinks that your file shouldn't be parsed.
For example, for c# file it shoul be parsed only if action==COMPILE. If
action==RESOURCE, it won't be parsed.

Please check if PsiManager.ShouldBuildPsi() returns 'false' for you file.

To modify this behavour, you have to modify that behavour by implmenting
your own checker:



internal class BuildProviderChecker : ISupportedByPSIChecker

{

public BuildPsiResult Check(IProjectFile projectFile)

{

// Check if project files is your's

}

}


--
Eugene Pasynkov
Developer
JetBrains, Inc
http://www.jetbrains.com
"Develop with pleasure!"
"Stefan Lieser" <stefan@lieser-online.de> wrote in message
news:fso6v6$pm7$1@is.intellij.net...

Hi,

>

I implemented the ProjectFileLanguageService und LanguageService classes
shown below. Now I have the problem that I get no PSI file in the
DaemonStage becaus PsiManager.PsiFile(m_DaemonProcess.ProjectFile) returns
always null. Please help! If I may send you more infos please tell me!

>

Regards,
Stefan Lieser

>
>

<code>
//---------- DaemonStage ---------------------------------
using JetBrains.ReSharper.Daemon;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.Shell.Progress;
using JetBrains.Util;

>

namespace NHibernatePlugin.Analysis.MappingFile
{
public class XmlAnalysisDaemonStageProcess : IDaemonStageProcess
{
private readonly IDaemonProcess m_DaemonProcess;

>

public XmlAnalysisDaemonStageProcess(IDaemonProcess daemonProcess)
{
m_DaemonProcess = daemonProcess;
}

>

public DaemonStageProcessResult Execute() {
Logger.LogMessage("NHibernatePlugin:
XmlAnalysisDaemonStageProcess.Execute called");
// Creating container to put highlightings to
DaemonStageProcessResult result = new
DaemonStageProcessResult();

>

// Getting PSI (AST) for the file being highlighted
IFile file = PsiManager.PsiFile(m_DaemonProcess.ProjectFile);
//********************************************
// file is always null
//********************************************

>

if (file == null) {
Logger.LogMessage(" NO PSI FILE !!! {0}",
m_DaemonProcess.ProjectFile.Name);
return result;
}

>

// Running visitor against the PSI
XmlAnalysisElementProcessor elementProcessor = new
XmlAnalysisElementProcessor(m_DaemonProcess);
file.ProcessDescendants(elementProcessor);

>

// Checking if the daemon is interrupted by user activity
if (m_DaemonProcess.InterruptFlag) {
throw new ProcessCancelledException();
}

>

// Fill in the result
result.FullyRehighlighted = true;
result.Highlightings =
elementProcessor.Highlightings.ToArray();

>

return result;
}
}
}

>

//---------- ProjectFileLanguageService ------------------
using System.Collections.Generic;
using System.Drawing;
using JetBrains.ComponentModel;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.ExtensionsAPI.Caches2;
using JetBrains.ReSharper.Psi.Parsing;
using JetBrains.ReSharper.Psi.Xml;
using JetBrains.ReSharper.Psi.Xml.Impl;
using JetBrains.Shell;
using JetBrains.Util;
using NHibernatePlugin.LanguageService;

>

namespace NHibernatePlugin.LanguageService
{
[ProjectFileLanguageService(new string[] { ".xml" }),
ShellComponentInterface(ProgramConfigurations.ALL),
ShellComponentImplementation, XmlLanguage]
public class MappingFileProjectFileLanguageService :
IDerivedProjectFileLanguageService, IShellComponent
{
public static ProjectFileType MAPPING_FILE = new
ProjectFileType("MappingFile");
private static readonly PsiLanguageType[]
POSSIBLE_PSI_LANGUAGE_TYPES = new PsiLanguageType[] {
MappingFileLanguageService.MAPPING_FILE };
private readonly IWordIndexLanguageProvider
m_WordIndexLanguageProvider = new XmlWordIndexLanguageProvider();

>

public ProjectFileType GetProjectFileType(IProjectFile file) {

>

Logger.LogMessage("MappingFileProjectFileLanguageService.GetProjectFileType
for file {0}", file.Name);
if (file.Name.EndsWith(".hbm.xml")) {
Logger.LogMessage(" Mapping File");
return MAPPING_FILE;
}
Logger.LogMessage(" UNKNOWN");
return ProjectFileType.UNKNOWN;
}

>

public PsiLanguageType GetPsiLanguageType(IProjectFile file) {

>

Logger.LogMessage("MappingFileProjectFileLanguageService.GetPsiLanguageType
for file {0}", file.Name);
return GetPsiLanguageType(file.LanguageType);
}

>

public PsiLanguageType GetPsiLanguageType(ProjectFileType
projectFileType) {

>

Logger.LogMessage("MappingFileProjectFileLanguageService.GetPsiLanguageType
for project file type {0}", projectFileType.Name);
if (projectFileType != MAPPING_FILE) {
Logger.LogMessage(" UNKNOWN");
return PsiLanguageType.UNKNOWN;
}
Logger.LogMessage(" Mapping File");
return MappingFileLanguageService.MAPPING_FILE;
}

>

public ILexerFactory CreateLexer(ProjectFileType languageType,
IBuffer buffer) {

>

Logger.LogMessage("MappingFileProjectFileLanguageService.CreateLexer for
language type {0}", languageType.Name);
if (languageType == MAPPING_FILE) {
Logger.LogMessage(" Mapping File");
return new
XmlLexerFactory(MappingFileLanguageService.MAPPING_FILE);
}
Logger.LogMessage(" UNKNOWN");
return null;
}

>

public ProjectFileType LanguageType {
get { return MAPPING_FILE; }
}

>

public Image Icon {
get { return null; }
}

>

public ICollection<PsiLanguageType> PossiblePsiLanguageTypes {
get {

>

Logger.LogMessage("MappingFileProjectFileLanguageService.PossiblePsiLanguageTypes");
return POSSIBLE_PSI_LANGUAGE_TYPES;
}
}

>

public IWordIndexLanguageProvider WordIndexLanguageProvider {
get {

>

Logger.LogMessage("MappingFileProjectFileLanguageService.WordIndexLanguageProvider");
// return
ProjectFileLanguageServiceManager.Instance.GetService(XmlProjectFileLanguageService.XML).WordIndexLanguageProvider;
return m_WordIndexLanguageProvider;
}
}

>

public void Init() {
}

>

public void Dispose() {
}
}
}

>
>

//---------- LanguageService -----------------------------

>

using JetBrains.ComponentModel;
using JetBrains.ProjectModel;
using JetBrains.ReSharper.Psi;
using JetBrains.ReSharper.Psi.ExtensionsAPI.Caches2;
using JetBrains.ReSharper.Psi.Parsing;
using JetBrains.ReSharper.Psi.Tree;
using JetBrains.ReSharper.Psi.Xml;
using JetBrains.Shell;
using JetBrains.Util;

>

namespace NHibernatePlugin.LanguageService
{
[LanguageService, ShellComponentInterface(ProgramConfigurations.ALL),
ShellComponentImplementation]
public class MappingFileLanguageService : XmlLanguageServiceBase,
IShellComponent
{
public static PsiLanguageType MAPPING_FILE = new
PsiLanguageType("MappingFile");
public const string MAPPING_FILE_LANGUAGEID = "MappingFile";

>

public MappingFileLanguageService()
: base(MAPPING_FILE) {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService ctor");
}

>

public override bool ShouldInvalidatePsiCache(IElement element,
PsiChangedElementType elementType) {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.ShouldInvalidatePsiCache called");
return true;
}

>

public override IParser CreateParser(ILexer lexer, ISolution
solution, IProject project, CheckForInterrupt checkForInterrupt) {
Logger.LogMessage("NHibernatePlugin: CreateParser for project
{0}, language ", project.Name, project.LanguageType.Name);
return new XmlParser(lexer, checkForInterrupt);
}

>

public override ILanguageCacheProvider CacheProvider {
get {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.CacheProvider called");
return new MappingFileLanguageCacheProvider(MAPPING_FILE);
}
}

>

public override ITypePresenter TypePresenter {
get {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.TypePresenter called");
return MappingFileTypePresenter.Instance;
}
}

>

public override PsiLanguageType LanguageType {
get {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.LanguageType called");
return MAPPING_FILE;
}
}

>

public static MappingFileLanguageService Instance {
get {
Logger.LogMessage("NHibernatePlugin:
MappingFileLanguageService.Instance called");
return
Shell.Instance.GetComponent<MappingFileLanguageService>();
}
}

>

public void Init() {
}

>

public void Dispose() {
}
}
}
</code>



0
Comment actions Permalink

Hi Eugene,

Eugene Pasynkov (JetBrains) wrote:

Please check if PsiManager.ShouldBuildPsi() returns 'false' for you file.


There is no PsiManager.ShouldBuildPsi()...

To modify this behavour, you have to modify that behavour by implmenting
your own checker:


internal class BuildProviderChecker : ISupportedByPSIChecker


Done that and it works now, thanx!!


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

0

Please sign in to leave a comment.