Search in sources :

Example 51 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class CompletionPathWithDotTest method testCompletionWithOneDot.

public void testCompletionWithOneDot() {
    // WithOneDot
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 37));
    myFixture.complete(CompletionType.BASIC, 1);
    List<String> strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.isEmpty());
    assertEquals(0, strings.size());
    // WithOneDotAndSlash
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 46));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assertTrue(strings.containsAll(Arrays.asList("./block", "./childWebPathFile", "./fileWithDotPath", "./fileWithTwoDotPath", "./childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // WithOneDotAndSlashTwoChars
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 56));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("./block");
    // WithOneDotAndDirectory
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 61));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("./childBlocks/childBlock");
    // WithOneDotAndDirectoryAndSlash
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 70));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("./childBlocks/childBlock");
    // WithOneDotAndDirectoryAndSlashTwoChars
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 80));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("./childBlocks/childBlock");
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 52 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class CompletionPathWithTwoDotTest method testCompletionParentWebPath.

public void testCompletionParentWebPath() {
    // WithTwoDotAndDirectoryAndSlashTwoChars
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(10, 60));
    myFixture.complete(CompletionType.BASIC, 1);
    List<String> strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.isEmpty());
    assertEquals(0, strings.size());
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition)

Example 53 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class CompletionTest method testCompletionInRootWebPathFile.

public void testCompletionInRootWebPathFile() {
    myFixture.configureByFile("public/rootWebPathFile.js");
    // NotFound
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 40));
    myFixture.complete(CompletionType.BASIC, 1);
    List<String> strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.isEmpty());
    assertEquals(0, strings.size());
    // True
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 37));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.containsAll(Arrays.asList("blocks/block", "blocks/childWebPathFile", "blocks/fileWithDotPath", "blocks/fileWithTwoDotPath", "blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // WithoutSlash
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 44));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.containsAll(Arrays.asList("blocks/block", "blocks/childWebPathFile", "blocks/fileWithDotPath", "blocks/fileWithTwoDotPath", "blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // TwoChars
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 36));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.containsAll(Arrays.asList("blocks/block", "blocks/childWebPathFile", "blocks/fileWithDotPath", "blocks/fileWithTwoDotPath", "blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // TwoDirectory
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 56));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("blocks/childBlocks/childBlock");
    // TwoDirectoryWithSlash
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 66));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("blocks/childBlocks/childBlock");
    // RootFound
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(7, 39));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assert element != null;
    assertEquals("'rootWebPathFile'", element.getText());
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) PsiElement(com.intellij.psi.PsiElement)

Example 54 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class CompletionTest method testCompletion.

public void testCompletion() {
    // NotFound
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 40));
    myFixture.complete(CompletionType.BASIC, 1);
    List<String> strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.isEmpty());
    assertEquals(0, strings.size());
    // True
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 37));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.containsAll(Arrays.asList("blocks/block", "blocks/childWebPathFile", "blocks/fileWithDotPath", "blocks/fileWithTwoDotPath", "blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // WithoutSlash
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 44));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.containsAll(Arrays.asList("blocks/block", "blocks/childWebPathFile", "blocks/fileWithDotPath", "blocks/fileWithTwoDotPath", "blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // TwoChars
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 36));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.containsAll(Arrays.asList("blocks/block", "blocks/childWebPathFile", "blocks/fileWithDotPath", "blocks/fileWithTwoDotPath", "blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // TwoDirectory
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 56));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("blocks/childBlocks/childBlock");
    // TwoDirectoryWithSlash
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 66));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("blocks/childBlocks/childBlock");
    // RootFound
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(7, 39));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    PsiElement element = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assert element != null;
    assertEquals("'rootWebPathFile'", element.getText());
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) PsiElement(com.intellij.psi.PsiElement)

Example 55 with LogicalPosition

use of com.intellij.openapi.editor.LogicalPosition in project WebStormRequireJsPlugin by Fedott.

the class CompletionTest method testCompletionWithBaseUrl.

public void testCompletionWithBaseUrl() {
    List<String> strings;
    PsiElement element;
    myFixture.configureByFiles("public/fileForTestBaseUrl.js", "public/mainWithBaseUrl.js");
    Settings.getInstance(getProject()).configFilePath = "mainWithBaseUrl.js";
    // NotFound
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(1, 40));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.isEmpty());
    assertEquals(0, strings.size());
    // 1
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(2, 29));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assertNull(strings);
    element = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assert element != null;
    assertEquals("'block'", element.getText());
    // 2
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(3, 34));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    element = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assert element != null;
    assertEquals("'childBlocks/childBlock'", element.getText());
    // 3
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(4, 39));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("childBlocks/childBlock");
    // 4
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(5, 41));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    element = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
    assert element != null;
    assertEquals("'childBlocks/childBlock'", element.getText());
    // 5
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(6, 33));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.containsAll(Arrays.asList("/blocks/block", "/blocks/childWebPathFile", "/blocks/fileWithDotPath", "/blocks/fileWithTwoDotPath", "/blocks/childBlocks/childBlock")));
    assertEquals(5, strings.size());
    // 6
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(7, 37));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("/blocks/block");
    // 7
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(8, 50));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.isEmpty());
    assertEquals(0, strings.size());
    // 8
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(9, 38));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings == null;
    assertCompletionSingle("./blocks/block");
    // 9
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(10, 30));
    myFixture.complete(CompletionType.BASIC, 1);
    strings = myFixture.getLookupElementStrings();
    assert strings != null;
    assertTrue(strings.isEmpty());
    assertEquals(0, strings.size());
}
Also used : LogicalPosition(com.intellij.openapi.editor.LogicalPosition) PsiElement(com.intellij.psi.PsiElement)

Aggregations

LogicalPosition (com.intellij.openapi.editor.LogicalPosition)97 Document (com.intellij.openapi.editor.Document)12 PsiElement (com.intellij.psi.PsiElement)12 Editor (com.intellij.openapi.editor.Editor)11 TextRange (com.intellij.openapi.util.TextRange)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 EditorEx (com.intellij.openapi.editor.ex.EditorEx)7 NotNull (org.jetbrains.annotations.NotNull)6 CaretModel (com.intellij.openapi.editor.CaretModel)5 RelativePoint (com.intellij.ui.awt.RelativePoint)5 JSFile (com.intellij.lang.javascript.psi.JSFile)4 EditorColorsManager (com.intellij.openapi.editor.colors.EditorColorsManager)4 TextAttributes (com.intellij.openapi.editor.markup.TextAttributes)4 Project (com.intellij.openapi.project.Project)4 PsiFile (com.intellij.psi.PsiFile)4 PsiReference (com.intellij.psi.PsiReference)4 PsiMultiReference (com.intellij.psi.impl.source.resolve.reference.impl.PsiMultiReference)4 Mark (com.maddyhome.idea.vim.common.Mark)4 HighlightManager (com.intellij.codeInsight.highlighting.HighlightManager)3 EditorHighlighter (com.intellij.openapi.editor.highlighter.EditorHighlighter)3