Skip to content

Commit

Permalink
Implemented proper context view and navigation
Browse files Browse the repository at this point in the history
Fixes #1585
  • Loading branch information
hurricup committed Oct 10, 2017
1 parent b0dc04e commit 0bf2d79
Show file tree
Hide file tree
Showing 5 changed files with 81 additions and 1 deletion.
5 changes: 5 additions & 0 deletions resources/META-INF/plugin.xml
Expand Up @@ -38,6 +38,7 @@
<li>Built-in subs, namespaces and variables usages are now highlighted and you may find usages for them</li>
<li>Spell checking is now available in Perl5 and POD files, by <a href="https://github.com/Camelcade/Perl5-IDEA/issues/1571">akashr</a></li>
<li>You may now annotate methods with <code>#@returns *</code>, meaning that method returns <code>$self</code>, <a href="https://github.com/Camelcade/Perl5-IDEA/issues/247">#247</a></li>
<li>Context view with <code>Alt + Q</code> and navigation with <code>Alt + Up/Down</code> works now, by <a href="https://github.com/Camelcade/Perl5-IDEA/issues/1585">johndunlap</a></li>
</ul>
</p>
<p>Fixes:
Expand Down Expand Up @@ -276,6 +277,10 @@

<lang.psiStructureViewFactory language="Perl5"
implementationClass="com.perl5.lang.perl.idea.structureView.PerlStructureViewFactory"/>
<declarationRangeHandler key="com.perl5.lang.perl.psi.PerlSubDefinitionElement"
implementationClass="com.perl5.lang.perl.idea.codeInsight.PerlDeclarationRangeHandler"/>
<declarationRangeHandler key="com.perl5.lang.perl.psi.PerlNamespaceDefinitionWithIdentifier"
implementationClass="com.perl5.lang.perl.idea.codeInsight.PerlDeclarationRangeHandler"/>

<typeHierarchyProvider language="Perl5"
implementationClass="com.perl5.lang.perl.idea.hierarchy.namespace.PerlTypeHierarchyProvider"/>
Expand Down
@@ -0,0 +1,53 @@
/*
* Copyright 2015-2017 Alexandr Evstigneev
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.perl5.lang.perl.idea.codeInsight;

import com.intellij.codeInsight.hint.DeclarationRangeHandler;
import com.intellij.openapi.util.TextRange;
import com.intellij.psi.PsiElement;
import com.perl5.lang.perl.psi.PerlNamespaceDefinitionWithIdentifier;
import com.perl5.lang.perl.psi.PerlSubDefinitionElement;
import com.perl5.lang.perl.psi.PsiPerlBlock;
import com.perl5.lang.perl.psi.PsiPerlNamespaceContent;
import org.jetbrains.annotations.NotNull;

public class PerlDeclarationRangeHandler implements DeclarationRangeHandler<PsiElement> {
@NotNull
@Override
public TextRange getDeclarationRange(@NotNull PsiElement container) {
if (container instanceof PerlSubDefinitionElement) {
PsiPerlBlock body = ((PerlSubDefinitionElement)container).getSubDefinitionBody();
if (body == null) {
return TextRange.EMPTY_RANGE;
}
return TextRange.create(container.getNode().getStartOffset(), body.getTextOffset());
}
else if (container instanceof PerlNamespaceDefinitionWithIdentifier) {
PsiPerlBlock block = ((PerlNamespaceDefinitionWithIdentifier)container).getBlock();
if (block != null) {
return TextRange.create(container.getNode().getStartOffset(), block.getTextOffset());
}
PsiPerlNamespaceContent content = ((PerlNamespaceDefinitionWithIdentifier)container).getNamespaceContent();
if (content != null) {
return TextRange.create(container.getNode().getStartOffset(), content.getTextOffset());
}
return TextRange.EMPTY_RANGE;
}

throw new IllegalArgumentException("Unhandled container: " + container);
}
}
Expand Up @@ -22,21 +22,28 @@
import com.intellij.lang.PsiStructureViewFactory;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.PsiFile;
import com.perl5.lang.perl.psi.PerlNamespaceDefinitionWithIdentifier;
import com.perl5.lang.perl.psi.PerlSubDefinitionElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

/**
* Created by hurricup on 15.08.2015.
*/
public class PerlStructureViewFactory implements PsiStructureViewFactory {


@Nullable
@Override
public StructureViewBuilder getStructureViewBuilder(final PsiFile psiFile) {
return new TreeBasedStructureViewBuilder() {
@NotNull
@Override
public StructureViewModel createStructureViewModel(@Nullable Editor editor) {
return new PerlStructureViewModel(psiFile, editor);
return new PerlStructureViewModel(psiFile, editor).withSuitableClasses(
PerlSubDefinitionElement.class,
PerlNamespaceDefinitionWithIdentifier.class
);
}

@Override
Expand Down
Expand Up @@ -18,8 +18,17 @@

import com.perl5.lang.perl.psi.properties.PerlIdentifierOwner;
import com.perl5.lang.perl.psi.properties.PerlNamespaceElementContainer;
import org.jetbrains.annotations.Nullable;

public interface PerlNamespaceDefinitionWithIdentifier extends PerlNamespaceDefinitionElement,
PerlNamespaceElementContainer,
PerlIdentifierOwner {

@Nullable
default PsiPerlBlock getBlock() {
return null;
}

@Nullable
default PsiPerlNamespaceContent getNamespaceContent() {return null;}
}
Expand Up @@ -67,6 +67,12 @@ public PerlNamespaceDefinitionMixin(@NotNull PerlNamespaceDefinitionStub stub, @
super(stub, nodeType);
}

@Nullable
@Override
public PsiPerlNamespaceContent getNamespaceContent() {
return PsiTreeUtil.getChildOfType(this, PsiPerlNamespaceContent.class);
}

@Nullable
@Override
public String getName() {
Expand Down

0 comments on commit 0bf2d79

Please sign in to comment.