当前位置: 首页>>代码示例>>Java>>正文


Java CompletionList.getItems方法代码示例

本文整理汇总了Java中org.eclipse.lsp4j.CompletionList.getItems方法的典型用法代码示例。如果您正苦于以下问题:Java CompletionList.getItems方法的具体用法?Java CompletionList.getItems怎么用?Java CompletionList.getItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.lsp4j.CompletionList的用法示例。


在下文中一共展示了CompletionList.getItems方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCompletion_javadoc

import org.eclipse.lsp4j.CompletionList; //导入方法依赖的package包/类
@Test
public void testCompletion_javadoc() throws Exception {
	IJavaProject javaProject = JavaCore.create(project);
	ICompilationUnit unit = (ICompilationUnit) javaProject.findElement(new Path("org/sample/TestJavadoc.java"));
	unit.becomeWorkingCopy(null);
	String joinOnCompletion = System.getProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION);
	try {
		System.setProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION, "true");
		int[] loc = findCompletionLocation(unit, "inner.");
		TextDocumentPositionParams position = JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]));
		String source = unit.getSource();
		changeDocument(unit, source, 3);
		Job.getJobManager().join(DocumentLifeCycleHandler.DOCUMENT_LIFE_CYCLE_JOBS, new NullProgressMonitor());
		changeDocument(unit, source, 4);
		CompletionList list = server.completion(position).join().getRight();
		for (CompletionItem item : list.getItems()) {
			server.resolveCompletionItem(item);
		}
		CompletionItem resolved = list.getItems().get(0);
		assertEquals("Test ", resolved.getDocumentation());
	} finally {
		unit.discardWorkingCopy();
		if (joinOnCompletion == null) {
			System.clearProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION);
		} else {
			System.setProperty(JDTLanguageServer.JAVA_LSP_JOIN_ON_COMPLETION, joinOnCompletion);
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:30,代码来源:CompletionHandlerTest.java

示例2: testCompletion_object

import org.eclipse.lsp4j.CompletionList; //导入方法依赖的package包/类
@Test
public void testCompletion_object() throws Exception{
	ICompilationUnit unit = getWorkingCopy(
			"src/java/Foo.java",
			"public class Foo {\n"+
					"	void foo() {\n"+
					"		Objec\n"+
					"	}\n"+
			"}\n");
	int[] loc = findCompletionLocation(unit, "Objec");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
	assertNotNull(list);
	assertFalse("No proposals were found",list.getItems().isEmpty());

	List<CompletionItem> items = list.getItems();
	for ( CompletionItem item : items) {
		assertTrue(isNotBlank(item.getLabel()));
		assertNotNull(item.getKind() );
		assertTrue(isNotBlank(item.getSortText()));
		//text edits are not set during calls to "completion"
		assertNull(item.getTextEdit());
		assertTrue(isNotBlank(item.getInsertText()));
		assertNotNull(item.getFilterText());
		assertFalse(item.getFilterText().contains(" "));
		assertTrue(item.getLabel().startsWith(item.getFilterText()));
		//Check contains data used for completionItem resolution
		@SuppressWarnings("unchecked")
		Map<String,String> data = (Map<String, String>) item.getData();
		assertNotNull(data);
		assertTrue(isNotBlank(data.get(CompletionResolveHandler.DATA_FIELD_URI)));
		assertTrue(isNotBlank(data.get(CompletionResolveHandler.DATA_FIELD_PROPOSAL_ID)));
		assertTrue(isNotBlank(data.get(CompletionResolveHandler.DATA_FIELD_REQUEST_ID)));
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:35,代码来源:CompletionHandlerTest.java

示例3: testCompletion_constructor

import org.eclipse.lsp4j.CompletionList; //导入方法依赖的package包/类
@Test
public void testCompletion_constructor() throws Exception{
	ICompilationUnit unit = getWorkingCopy(
			"src/java/Foo.java",
			"public class Foo {\n"+
					"	void foo() {\n"+
					"		Object o = new O\n"+
					"	}\n"+
			"}\n");
	int[] loc = findCompletionLocation(unit, "new O");
	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();
	assertNotNull(list);
	assertFalse("No proposals were found",list.getItems().isEmpty());

	List<CompletionItem> items = new ArrayList<>(list.getItems());
	Comparator<CompletionItem> comparator = (CompletionItem a, CompletionItem b) -> a.getSortText().compareTo(b.getSortText());
	Collections.sort(items, comparator);
	CompletionItem ctor = items.get(0);
	assertEquals("Object()", ctor.getLabel());
	assertEquals("Object", ctor.getInsertText());

	CompletionItem resolvedItem = server.resolveCompletionItem(ctor).join();
	assertNotNull(resolvedItem);
	TextEdit te = resolvedItem.getTextEdit();
	assertNotNull(te);
	assertEquals("Object()",te.getNewText());
	assertNotNull(te.getRange());
	Range range = te.getRange();
	assertEquals(2, range.getStart().getLine());
	assertEquals(17, range.getStart().getCharacter());
	assertEquals(2, range.getEnd().getLine());
	assertEquals(18, range.getEnd().getCharacter());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:34,代码来源:CompletionHandlerTest.java

示例4: testCompletion_package

import org.eclipse.lsp4j.CompletionList; //导入方法依赖的package包/类
@Test
public void testCompletion_package() throws JavaModelException{
	ClientPreferences mockCapabilies = Mockito.mock(ClientPreferences.class);
	Mockito.when(preferenceManager.getClientPreferences()).thenReturn(mockCapabilies);

	ICompilationUnit unit = getWorkingCopy(
			"src/org/sample/Baz.java",
			"package o"+
					"public class Baz {\n"+
			"}\n");

	int[] loc = findCompletionLocation(unit, "package o");

	CompletionList list = server.completion(JsonMessageHelper.getParams(createCompletionRequest(unit, loc[0], loc[1]))).join().getRight();

	assertNotNull(list);
	List<CompletionItem> items = new ArrayList<>(list.getItems());
	assertTrue(items.size() > 1);
	items.sort((i1, i2) -> i1.getSortText().compareTo(i2.getSortText()));

	CompletionItem item = items.get(0);
	// current package should appear 1st
	assertEquals("org.sample",item.getLabel());

	CompletionItem resolvedItem = server.resolveCompletionItem(item).join();
	assertNotNull(resolvedItem);
	TextEdit te = item.getTextEdit();
	assertNotNull(te);
	assertEquals("org.sample", te.getNewText());
	assertNotNull(te.getRange());
	Range range = te.getRange();
	assertEquals(0, range.getStart().getLine());
	assertEquals(8, range.getStart().getCharacter());
	assertEquals(0, range.getEnd().getLine());
	assertEquals(15, range.getEnd().getCharacter());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:37,代码来源:CompletionHandlerTest.java

示例5: createCompletionList

import org.eclipse.lsp4j.CompletionList; //导入方法依赖的package包/类
public CompletionList createCompletionList(final Document document, final XtextResource resource, final TextDocumentPositionParams params, final CancelIndicator cancelIndicator) {
  try {
    final CompletionList result = new CompletionList();
    result.setIsIncomplete(true);
    final IdeContentProposalAcceptor acceptor = this.proposalAcceptorProvider.get();
    final int caretOffset = document.getOffSet(params.getPosition());
    final Position caretPosition = params.getPosition();
    final TextRegion position = new TextRegion(caretOffset, 0);
    try {
      this.createProposals(document.getContents(), position, caretOffset, resource, acceptor);
    } catch (final Throwable _t) {
      if (_t instanceof Throwable) {
        final Throwable t = (Throwable)_t;
        boolean _isOperationCanceledException = this.operationCanceledManager.isOperationCanceledException(t);
        boolean _not = (!_isOperationCanceledException);
        if (_not) {
          throw t;
        }
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
    final Procedure2<ContentAssistEntry, Integer> _function = (ContentAssistEntry it, Integer idx) -> {
      final CompletionItem item = this.toCompletionItem(it, caretOffset, caretPosition, document);
      item.setSortText(Strings.padStart(Integer.toString((idx).intValue()), 5, '0'));
      List<CompletionItem> _items = result.getItems();
      _items.add(item);
    };
    IterableExtensions.<ContentAssistEntry>forEach(acceptor.getEntries(), _function);
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
开发者ID:eclipse,项目名称:xtext-core,代码行数:35,代码来源:ContentAssistService.java


注:本文中的org.eclipse.lsp4j.CompletionList.getItems方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。