-
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from nette-intellij/mn-variable-context
Mn variable context
- Loading branch information
Showing
101 changed files
with
2,575 additions
and
1,012 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
ideaVersion = 2020.3 | ||
phpPluginVersion = 203.5981.155 | ||
ideaVersion = 2021.1 | ||
phpPluginVersion = 211.6693.111 | ||
#toolboxPluginVersion = 0.4.6 | ||
#annotationPluginVersion = 5.3 |
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
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
48 changes: 48 additions & 0 deletions
48
...main/java/com/jantvrdik/intellij/latte/completion/handlers/PhpNamespaceInsertHandler.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,48 @@ | ||
package com.jantvrdik.intellij.latte.completion.handlers; | ||
|
||
import com.intellij.codeInsight.completion.InsertionContext; | ||
import com.intellij.codeInsight.lookup.LookupElement; | ||
import com.intellij.openapi.editor.EditorModificationUtil; | ||
import com.intellij.psi.PsiDocumentManager; | ||
import com.jetbrains.php.completion.insert.PhpReferenceInsertHandler; | ||
import com.jetbrains.php.lang.psi.elements.PhpNamespace; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class PhpNamespaceInsertHandler extends PhpReferenceInsertHandler { | ||
|
||
private static final PhpNamespaceInsertHandler instance = new PhpNamespaceInsertHandler(); | ||
|
||
public PhpNamespaceInsertHandler() { | ||
super(); | ||
} | ||
|
||
public void handleInsert(@NotNull InsertionContext context, @NotNull LookupElement lookupElement) { | ||
final Object object = lookupElement.getObject(); | ||
String fqn = object instanceof PhpNamespace ? ((PhpNamespace) object).getParentNamespaceName() : ""; | ||
if (fqn.isEmpty()) { | ||
return; | ||
} | ||
|
||
int startOffset = context.getEditor().getCaretModel().getOffset(); | ||
String fileText = context.getEditor().getDocument().getText(); | ||
String current = fileText.substring(0, startOffset); | ||
int lastSpace = current.lastIndexOf(" "); | ||
current = current.substring(lastSpace + 1); | ||
|
||
if (fqn.startsWith("\\")) { | ||
fqn = fqn.substring(1); | ||
} | ||
|
||
context.getDocument().insertString(context.getStartOffset(), fqn); | ||
|
||
if (!current.endsWith("\\")) { | ||
EditorModificationUtil.insertStringAtCaret(context.getEditor(), "\\"); | ||
} | ||
|
||
PsiDocumentManager.getInstance(context.getProject()).commitDocument(context.getDocument()); | ||
} | ||
|
||
public static PhpNamespaceInsertHandler getInstance() { | ||
return instance; | ||
} | ||
} |
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
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
Oops, something went wrong.