-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Added support for completion and file reference (Ctrl+Click, Rename…
…..) for various file and folder related functions and methods - Added file mode completion support for SplFileInfo::openFile - Added basic file url completion support for header('Location: ... and header('Content-Location: ...
- Loading branch information
Showing
11 changed files
with
390 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/net/king2500/plugins/PhpAdvancedAutoComplete/GenericFileLookupElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package net.king2500.plugins.PhpAdvancedAutoComplete; | ||
|
||
import com.intellij.codeInsight.completion.InsertHandler; | ||
import com.intellij.codeInsight.completion.InsertionContext; | ||
import com.intellij.codeInsight.lookup.LookupElement; | ||
import com.intellij.codeInsight.lookup.LookupElementPresentation; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFileSystemItem; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: Thomas | ||
* Date: 16.08.13 | ||
* Time: 21:59 | ||
*/ | ||
public class GenericFileLookupElement extends LookupElement { | ||
private String fileName; | ||
private PsiFileSystemItem psiFile; | ||
private PsiElement psiElement = null; | ||
|
||
@Nullable | ||
private InsertHandler<LookupElement> insertHandler = null; | ||
|
||
public GenericFileLookupElement(String fileName, PsiFileSystemItem psiFile) { | ||
this.fileName = fileName; | ||
this.psiFile = psiFile; | ||
} | ||
|
||
public GenericFileLookupElement(String fileName, PsiFileSystemItem psiFile, PsiElement psiElement, InsertHandler<LookupElement> insertHandler) { | ||
this.fileName = fileName; | ||
this.psiFile = psiFile; | ||
this.insertHandler = insertHandler; | ||
this.psiElement = psiElement; | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public String getLookupString() { | ||
return fileName; | ||
} | ||
|
||
@NotNull | ||
public Object getObject() { | ||
return this.psiElement != null ? this.psiElement : super.getObject(); | ||
} | ||
|
||
public void handleInsert(InsertionContext context) { | ||
if (this.insertHandler != null) { | ||
this.insertHandler.handleInsert(context, this); | ||
} | ||
} | ||
|
||
public void renderElement(LookupElementPresentation presentation) { | ||
presentation.setItemText(getLookupString()); | ||
presentation.setIcon(psiFile.getIcon(0)); | ||
//presentation.setTypeText(VfsUtil.getRelativePath(psiFile.getContainingDirectory().getVirtualFile(), psiFile.getProject().getBaseDir(), '/')); | ||
//presentation.setTypeGrayed(true); | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/net/king2500/plugins/PhpAdvancedAutoComplete/GenericFileReference.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package net.king2500.plugins.PhpAdvancedAutoComplete; | ||
|
||
import com.intellij.codeInsight.lookup.LookupElement; | ||
import com.intellij.psi.*; | ||
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; | ||
import net.king2500.plugins.PhpAdvancedAutoComplete.utils.FileHelper; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: Thomas | ||
* Date: 16.08.13 | ||
* Time: 21:29 | ||
*/ | ||
public class GenericFileReference extends PsiReferenceBase<PsiElement> implements PsiReference { | ||
|
||
private String fileName; | ||
private int fileType; | ||
|
||
public GenericFileReference(@NotNull StringLiteralExpression element, int type) { | ||
super(element); | ||
|
||
fileName = element.getText().substring( | ||
element.getValueRange().getStartOffset(), | ||
element.getValueRange().getEndOffset() | ||
); | ||
|
||
fileType = type; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public PsiElement resolve() { | ||
Map<String, PsiFileSystemItem> filesByName = FileHelper.getRelativeFilesByName(getElement().getContainingFile(), fileType); | ||
|
||
return filesByName.get(fileName); | ||
} | ||
|
||
@NotNull | ||
@Override | ||
public Object[] getVariants() { | ||
List<LookupElement> results = new ArrayList<LookupElement>(); | ||
|
||
Map<String, PsiFileSystemItem> filesByName = FileHelper.getRelativeFilesByName(getElement().getContainingFile(), fileType); | ||
for (Map.Entry<String, PsiFileSystemItem> entry : filesByName.entrySet()) { | ||
results.add( | ||
new GenericFileLookupElement(entry.getKey(), entry.getValue()) | ||
); | ||
} | ||
|
||
return results.toArray(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/net/king2500/plugins/PhpAdvancedAutoComplete/PhpFileReferenceContributor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package net.king2500.plugins.PhpAdvancedAutoComplete; | ||
|
||
import com.intellij.patterns.PlatformPatterns; | ||
import com.intellij.psi.*; | ||
import com.intellij.util.ProcessingContext; | ||
import com.jetbrains.php.lang.PhpLanguage; | ||
import com.jetbrains.php.lang.psi.elements.FunctionReference; | ||
import com.jetbrains.php.lang.psi.elements.MethodReference; | ||
import com.jetbrains.php.lang.psi.elements.ParameterList; | ||
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression; | ||
import com.jetbrains.php.lang.psi.elements.impl.NewExpressionImpl; | ||
import net.king2500.plugins.PhpAdvancedAutoComplete.utils.FileHelper; | ||
import net.king2500.plugins.PhpAdvancedAutoComplete.utils.PhpHelper; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* Created with IntelliJ IDEA. | ||
* User: Thomas | ||
* Date: 16.08.13 | ||
* Time: 21:11 | ||
*/ | ||
public class PhpFileReferenceContributor extends PsiReferenceContributor { | ||
@Override | ||
public void registerReferenceProviders(PsiReferenceRegistrar psiReferenceRegistrar) { | ||
psiReferenceRegistrar.registerReferenceProvider( | ||
PlatformPatterns.psiElement(StringLiteralExpression.class).withLanguage(PhpLanguage.INSTANCE), | ||
new PsiReferenceProvider() { | ||
@NotNull | ||
@Override | ||
public PsiReference[] getReferencesByElement(@NotNull PsiElement psiElement, @NotNull ProcessingContext processingContext) { | ||
if(!(psiElement.getContext() instanceof ParameterList)) { | ||
return new PsiReference[0]; | ||
} | ||
|
||
ParameterList parameterList = (ParameterList)psiElement.getContext(); | ||
|
||
if (parameterList == null || !(parameterList.getContext() instanceof FunctionReference || parameterList.getContext() instanceof MethodReference || parameterList.getContext() instanceof NewExpressionImpl)) { | ||
return new PsiReference[0]; | ||
} | ||
|
||
String funcName = PhpHelper.getCanonicalFuncName(psiElement.getParent().getParent()); | ||
int paramIndex = PhpHelper.getParameterIndex(psiElement); | ||
|
||
if(Arrays.asList(PhpCompletionTokens.fileFuncs).contains(funcName + ":" + paramIndex + ":f")) { | ||
return new PsiReference[]{ new GenericFileReference((StringLiteralExpression)psiElement, FileHelper.TYPE_FILE ) }; | ||
} | ||
else if(Arrays.asList(PhpCompletionTokens.fileFuncs).contains(funcName + ":" + paramIndex + ":d")) { | ||
return new PsiReference[]{ new GenericFileReference((StringLiteralExpression)psiElement, FileHelper.TYPE_DIR ) }; | ||
} | ||
else if(Arrays.asList(PhpCompletionTokens.fileFuncs).contains(funcName + ":" + paramIndex)) { | ||
return new PsiReference[]{ new GenericFileReference((StringLiteralExpression)psiElement, FileHelper.TYPE_ALL ) }; | ||
} | ||
|
||
return new PsiReference[0]; | ||
} | ||
} | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.