类org.eclipse.lsp4j.SymbolInformation源码实例Demo

下面列出了怎么用org.eclipse.lsp4j.SymbolInformation的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: lsp4intellij   文件: WorkspaceSymbolProvider.java
private LSPNavigationItem createNavigationItem(LSPSymbolResult result, Project project) {
  final SymbolInformation information = result.getSymbolInformation();
  final Location location = information.getLocation();
  final VirtualFile file = FileUtils.URIToVFS(location.getUri());

  if (file != null) {
    final LSPIconProvider iconProviderFor = GUIUtils.getIconProviderFor(result.getDefinition());
    final LSPLabelProvider labelProvider = GUIUtils.getLabelProviderFor(result.getDefinition());
    return new LSPNavigationItem(labelProvider.symbolNameFor(information, project),
            labelProvider.symbolLocationFor(information, project), iconProviderFor.getSymbolIcon(information.getKind()),
            project, file,
            location.getRange().getStart().getLine(),
            location.getRange().getStart().getCharacter());
  } else {
    return null;
  }
}
 
源代码2 项目: lemminx   文件: XMLSymbolsProvider.java
private void findSymbolInformations(DOMNode node, String container, List<SymbolInformation> symbols,
		boolean ignoreNode, AtomicLong limit, CancelChecker cancelChecker) throws BadLocationException {
	if (!isNodeSymbol(node)) {
		return;
	}
	String name = "";
	if (!ignoreNode) {
		name = nodeToName(node);
		DOMDocument xmlDocument = node.getOwnerDocument();
		Range range = getSymbolRange(node);
		Location location = new Location(xmlDocument.getDocumentURI(), range);
		SymbolInformation symbol = new SymbolInformation(name, getSymbolKind(node), location, container);

		checkLimit(limit);
		symbols.add(symbol);
	}
	final String containerName = name;
	node.getChildren().forEach(child -> {
		try {
			findSymbolInformations(child, containerName, symbols, false, limit, cancelChecker);
		} catch (BadLocationException e) {
			LOGGER.log(Level.SEVERE, "XMLSymbolsProvider was given a BadLocation by the provided 'node' variable",
					e);
		}
	});
}
 
源代码3 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testNestedSymbol() {
	String xmlText = "<project><inside></inside></project>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 36, xmlDocument);
	currentSymbolInfo = createSymbolInformation("project", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 9, 26, xmlDocument);
	currentSymbolInfo = createSymbolInformation("inside", SymbolKind.Field, currentLocation, "project");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码4 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testNestedTwice() {
	String xmlText = "<a><b><c></c></b></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 21, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 17, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 6, 13, xmlDocument);
	currentSymbolInfo = createSymbolInformation("c", SymbolKind.Field, currentLocation, "b");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码5 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testNestedSelfClosingTag() {
	String xmlText = "<a><b/></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 11, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 7, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码6 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testNestedUnclosedTag() {
	String xmlText = "<a><b></a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 10, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 6, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码7 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testAllTagsUnclosed() {
	String xmlText = "<a><b>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 6, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 3, 6, xmlDocument);
	currentSymbolInfo = createSymbolInformation("b", SymbolKind.Field, currentLocation, "a");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码8 项目: lemminx   文件: XMLSymbolInformationsTest.java
private void assertSymbols(List<SymbolInformation> expectedSymbolList, List<SymbolInformation> actualSymbolList) {
	assertEquals(expectedSymbolList.size(), actualSymbolList.size());

	SymbolInformation currentExpectedSymbol;
	SymbolInformation currentActualSymbol;

	for (int i = 0; i < expectedSymbolList.size(); i++) {
		currentExpectedSymbol = expectedSymbolList.get(i);
		currentActualSymbol = actualSymbolList.get(i);
		assertEquals(currentExpectedSymbol.getName(), currentActualSymbol.getName(),"Symbol index " + i);
		assertEquals(currentExpectedSymbol.getKind(), currentActualSymbol.getKind(),"Symbol index " + i);
		assertEquals(currentExpectedSymbol.getContainerName(),
				currentActualSymbol.getContainerName(),"Symbol index " + i);
		assertEquals(currentExpectedSymbol.getLocation(), currentActualSymbol.getLocation(),"Symbol index " + i);
		assertEquals(currentExpectedSymbol.getDeprecated(),
				currentActualSymbol.getDeprecated(),"Symbol index " + i);
	}
}
 
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> getDocumentSymbols() {
	return CompletableFuture.supplyAsync(() -> {
		if (textDocumentItem.getUri().endsWith(".xml")) {
			try {
				List<Either<SymbolInformation, DocumentSymbol>> symbolInformations = new ArrayList<>();
				NodeList routeNodes = parserFileHelper.getRouteNodes(textDocumentItem);
				if (routeNodes != null) {
					symbolInformations.addAll(convertToSymbolInformation(routeNodes));
				}
				NodeList camelContextNodes = parserFileHelper.getCamelContextNodes(textDocumentItem);
				if (camelContextNodes != null) {
					symbolInformations.addAll(convertToSymbolInformation(camelContextNodes));
				}
				return symbolInformations;
			} catch (Exception e) {
				LOGGER.error(CANNOT_DETERMINE_DOCUMENT_SYMBOLS, e);
			}
		}
		return Collections.emptyList();
	});
}
 
源代码10 项目: lsp4j   文件: SymbolInformationTypeAdapter.java
public void write(final JsonWriter out, final SymbolInformation value) throws IOException {
  if (value == null) {
  	out.nullValue();
  	return;
  }
  
  out.beginObject();
  out.name("name");
  writeName(out, value.getName());
  out.name("kind");
  writeKind(out, value.getKind());
  out.name("deprecated");
  writeDeprecated(out, value.getDeprecated());
  out.name("location");
  writeLocation(out, value.getLocation());
  out.name("containerName");
  writeContainerName(out, value.getContainerName());
  out.endObject();
}
 
@Test
void testNoExceptionWithJavaFile() throws Exception {
	final TestLogAppender appender = new TestLogAppender();
	final Logger logger = Logger.getRootLogger();
	logger.addAppender(appender);
	File f = new File("src/test/resources/workspace/camel.java");
	try (FileInputStream fis = new FileInputStream(f)) {
		CamelLanguageServer camelLanguageServer = initializeLanguageServer(fis, ".java");
		CompletableFuture<List<Either<SymbolInformation,DocumentSymbol>>> documentSymbolFor = getDocumentSymbolFor(camelLanguageServer);
		List<Either<SymbolInformation, DocumentSymbol>> symbolsInformation = documentSymbolFor.get();
		assertThat(symbolsInformation).isEmpty();
		for (LoggingEvent loggingEvent : appender.getLog()) {
			if (loggingEvent.getMessage() != null) {
				assertThat((String)loggingEvent.getMessage()).doesNotContain(DocumentSymbolProcessor.CANNOT_DETERMINE_DOCUMENT_SYMBOLS);
			}
		}
	}
}
 
源代码12 项目: xtext-core   文件: WorkspaceSymbolService.java
public List<? extends SymbolInformation> getSymbols(
	String query,
	IResourceAccess resourceAccess,
	IResourceDescriptions indexData,
	CancelIndicator cancelIndicator
) {
	List<SymbolInformation> result = new LinkedList<>();
	for (IResourceDescription resourceDescription : indexData.getAllResourceDescriptions()) {
		operationCanceledManager.checkCanceled(cancelIndicator);
		IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(resourceDescription.getURI());
		if (resourceServiceProvider != null) {
			DocumentSymbolService documentSymbolService = resourceServiceProvider.get(DocumentSymbolService.class);
			if (documentSymbolService != null) {
				result.addAll(documentSymbolService.getSymbols(resourceDescription, query, resourceAccess, cancelIndicator));
			}
		}
	}
	return result;
}
 
源代码13 项目: netbeans   文件: TextDocumentServiceImpl.java
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(DocumentSymbolParams params) {
    JavaSource js = getSource(params.getTextDocument().getUri());
    List<Either<SymbolInformation, DocumentSymbol>> result = new ArrayList<>();
    try {
        js.runUserActionTask(cc -> {
            cc.toPhase(JavaSource.Phase.RESOLVED);
            for (Element tel : cc.getTopLevelElements()) {
                DocumentSymbol ds = element2DocumentSymbol(cc, tel);
                if (ds != null)
                    result.add(Either.forRight(ds));
            }
        }, true);
    } catch (IOException ex) {
        //TODO: include stack trace:
        client.logMessage(new MessageParams(MessageType.Error, ex.getMessage()));
    }

    return CompletableFuture.completedFuture(result);
}
 
源代码14 项目: eclipse.jdt.ls   文件: SyntaxServerTest.java
@Test
public void testDocumentSymbol() throws Exception {
	when(preferenceManager.getClientPreferences().isHierarchicalDocumentSymbolSupported()).thenReturn(Boolean.TRUE);

	URI fileURI = openFile("maven/salut4", "src/main/java/java/Foo.java");
	TextDocumentIdentifier identifier = new TextDocumentIdentifier(fileURI.toString());
	DocumentSymbolParams params = new DocumentSymbolParams(identifier);
	List<Either<SymbolInformation, DocumentSymbol>> result = server.documentSymbol(params).join();
	assertNotNull(result);
	assertEquals(2, result.size());
	Either<SymbolInformation, DocumentSymbol> symbol = result.get(0);
	assertTrue(symbol.isRight());
	assertEquals("java", symbol.getRight().getName());
	assertEquals(SymbolKind.Package, symbol.getRight().getKind());
	symbol = result.get(1);
	assertTrue(symbol.isRight());
	assertEquals("Foo", symbol.getRight().getName());
	assertEquals(SymbolKind.Class, symbol.getRight().getKind());
	List<DocumentSymbol> children = symbol.getRight().getChildren();
	assertNotNull(children);
	assertEquals(1, children.size());
	assertEquals("main(String[])", children.get(0).getName());
	assertEquals(SymbolKind.Method, children.get(0).getKind());
}
 
源代码15 项目: eclipse.jdt.ls   文件: DocumentSymbolHandlerTest.java
@Test
public void testSyntheticMember() throws Exception {
	String className = "org.apache.commons.lang3.text.StrTokenizer";
	List<? extends SymbolInformation> symbols = getSymbols(className);
	boolean overloadedMethod1Found = false;
	boolean overloadedMethod2Found = false;
	String overloadedMethod1 = "getCSVInstance(String)";
	String overloadedMethod2 = "reset()";
	for (SymbolInformation symbol : symbols) {
		Location loc = symbol.getLocation();
		assertTrue("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid location.",
				loc != null && isValid(loc.getRange()));
		assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + " - invalid name",
				symbol.getName().startsWith("access$"));
		assertFalse("Class: " + className + ", Symbol:" + symbol.getName() + "- invalid name",
				symbol.getName().equals("<clinit>"));
		if (overloadedMethod1.equals(symbol.getName())) {
			overloadedMethod1Found = true;
		}
		if (overloadedMethod2.equals(symbol.getName())) {
			overloadedMethod2Found = true;
		}
	}
	assertTrue("The " + overloadedMethod1 + " method hasn't been found", overloadedMethod1Found);
	assertTrue("The " + overloadedMethod2 + " method hasn't been found", overloadedMethod2Found);
}
 
源代码16 项目: xtext-core   文件: DocumentSymbolService.java
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(XtextResource resource,
		CancelIndicator cancelIndicator) {
	String uri = uriExtensions.toUriString(resource.getURI());
	ArrayList<SymbolInformation> infos = new ArrayList<>();
	List<DocumentSymbol> rootSymbols = Lists
			.transform(hierarchicalDocumentSymbolService.getSymbols(resource, cancelIndicator), Either::getRight);
	for (DocumentSymbol rootSymbol : rootSymbols) {
		Iterable<DocumentSymbol> symbols = Traverser.forTree(DocumentSymbol::getChildren)
				.depthFirstPreOrder(rootSymbol);
		Function1<? super DocumentSymbol, ? extends String> containerNameProvider = (DocumentSymbol symbol) -> {
			DocumentSymbol firstSymbol = IterableExtensions.findFirst(symbols, (DocumentSymbol it) -> {
				return it != symbol && !IterableExtensions.isNullOrEmpty(it.getChildren())
						&& it.getChildren().contains(symbol);
			});
			if (firstSymbol != null) {
				return firstSymbol.getName();
			}
			return null;
		};
		for (DocumentSymbol s : symbols) {
			infos.add(createSymbol(uri, s, containerNameProvider));
		}
	}
	return Lists.transform(infos, Either::forLeft);
}
 
源代码17 项目: xtext-core   文件: AbstractLanguageServerTest.java
protected void testDocumentSymbol(final Procedure1<? super DocumentSymbolConfiguraiton> configurator) {
  try {
    @Extension
    final DocumentSymbolConfiguraiton configuration = new DocumentSymbolConfiguraiton();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final String fileUri = this.initializeContext(configuration).getUri();
    TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
    DocumentSymbolParams _documentSymbolParams = new DocumentSymbolParams(_textDocumentIdentifier);
    final CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> symbolsFuture = this.languageServer.documentSymbol(_documentSymbolParams);
    final List<Either<SymbolInformation, DocumentSymbol>> symbols = symbolsFuture.get();
    Procedure1<? super List<Either<SymbolInformation, DocumentSymbol>>> _assertSymbols = configuration.getAssertSymbols();
    boolean _tripleNotEquals = (_assertSymbols != null);
    if (_tripleNotEquals) {
      configuration.getAssertSymbols().apply(symbols);
    } else {
      final Function1<Either<SymbolInformation, DocumentSymbol>, Object> _function = (Either<SymbolInformation, DocumentSymbol> it) -> {
        Object _xifexpression = null;
        if (this.hierarchicalDocumentSymbolSupport) {
          _xifexpression = it.getRight();
        } else {
          _xifexpression = it.getLeft();
        }
        return _xifexpression;
      };
      final List<Object> unwrappedSymbols = ListExtensions.<Either<SymbolInformation, DocumentSymbol>, Object>map(symbols, _function);
      final String actualSymbols = this.toExpectation(unwrappedSymbols);
      this.assertEquals(configuration.getExpectedSymbols(), actualSymbols);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
源代码18 项目: groovy-language-server   文件: GroovyServices.java
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(
		DocumentSymbolParams params) {
	URI uri = URI.create(params.getTextDocument().getUri());
	recompileIfContextChanged(uri);

	DocumentSymbolProvider provider = new DocumentSymbolProvider(astVisitor);
	return provider.provideDocumentSymbols(params.getTextDocument());
}
 
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(XtextResource resource,
		CancelIndicator cancelIndicator) {
	HashMap<EObject, DocumentSymbol> allSymbols = new HashMap<>();
	ArrayList<DocumentSymbol> rootSymbols = new ArrayList<>();
	Iterator<Object> itr = getAllContents(resource);
	while (itr.hasNext()) {
		operationCanceledManager.checkCanceled(cancelIndicator);
		Optional<EObject> next = toEObject(itr.next());
		if (next.isPresent()) {
			EObject object = next.get();
			DocumentSymbol symbol = symbolMapper.toDocumentSymbol(object);
			if (isValid(symbol)) {
				allSymbols.put(object, symbol);
				EObject parent = object.eContainer();
				if (parent == null) {
					rootSymbols.add(symbol);
				} else {
					DocumentSymbol parentSymbol = allSymbols.get(parent);
					while (parentSymbol == null && parent != null) {
						parent = parent.eContainer();
						parentSymbol = allSymbols.get(parent);
					}
					if (parentSymbol == null) {
						rootSymbols.add(symbol);
					} else {
						parentSymbol.getChildren().add(symbol);
					}
				}
			}
		}
	}
	return rootSymbols.stream().map(symbol -> Either.<SymbolInformation, DocumentSymbol>forRight(symbol))
			.collect(Collectors.toList());
}
 
public static SymbolInformation astNodeToSymbolInformation(Variable node, URI uri, String parentName) {
	if (!(node instanceof ASTNode)) {
		// DynamicVariable isn't an ASTNode
		return null;
	}
	ASTNode astVar = (ASTNode) node;
	return new SymbolInformation(node.getName(), astNodeToSymbolKind(astVar), astNodeToLocation(astVar, uri),
			parentName);
}
 
源代码21 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testSingleSymbol() {
	String xmlText = "<project></project>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 19, xmlDocument);
	currentSymbolInfo = createSymbolInformation("project", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码22 项目: lsp4j   文件: SymbolInformationTypeAdapter.java
public SymbolInformation read(final JsonReader in) throws IOException {
  JsonToken nextToken = in.peek();
  if (nextToken == JsonToken.NULL) {
  	return null;
  }
  
  SymbolInformation result = new SymbolInformation();
  in.beginObject();
  while (in.hasNext()) {
  	String name = in.nextName();
  	switch (name) {
  	case "name":
  		result.setName(readName(in));
  		break;
  	case "kind":
  		result.setKind(readKind(in));
  		break;
  	case "deprecated":
  		result.setDeprecated(readDeprecated(in));
  		break;
  	case "location":
  		result.setLocation(readLocation(in));
  		break;
  	case "containerName":
  		result.setContainerName(readContainerName(in));
  		break;
  	default:
  		in.skipValue();
  	}
  }
  in.endObject();
  return result;
}
 
源代码23 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testSelfClosingTag() {
	String xmlText = "<a/>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 4, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码24 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void testUnclosedTag() {
	String xmlText = "<a>";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 3, xmlDocument);
	currentSymbolInfo = createSymbolInformation("a", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码25 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void internalDTD() {
	String xmlText = "<!DOCTYPE br [\n" + //
			"  	<!ELEMENT br EMPTY>\n" + //
			"	<!ATTLIST br\n" + //
			"		%all;>\n" + //
			"]>\n" + //
			"<br />";
	String testURI = "test.xml";
	initializeTestObjects(xmlText, testURI);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 63, xmlDocument);
	currentSymbolInfo = createSymbolInformation("DOCTYPE:br", SymbolKind.Struct, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 18, 37, xmlDocument);
	currentSymbolInfo = createSymbolInformation("br", SymbolKind.Property, currentLocation, "DOCTYPE:br");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 54, 59, xmlDocument);
	currentSymbolInfo = createSymbolInformation("%all;", SymbolKind.Key, currentLocation, "DOCTYPE:br");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 64, 70, xmlDocument);
	currentSymbolInfo = createSymbolInformation("br", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);
}
 
源代码26 项目: lemminx   文件: XMLSymbolInformationsTest.java
@Test
public void exceedSymbolLimit() {
	String xmlText = "<!DOCTYPE br [\n" + //
			"  	<!ELEMENT br EMPTY>\n" + //
			"	<!ATTLIST br\n" + //
			"		%all;>\n" + //
			"]>\n" + //
			"<br />";
	String testURI = "test.xml";
	XMLSymbolSettings settings = new XMLSymbolSettings();
	settings.setMaxItemsComputed(4);
	initializeTestObjects(xmlText, testURI, settings);

	List<SymbolInformation> expectedSymbolInfos = new ArrayList<SymbolInformation>();
	currentLocation = createLocation(testURI, 0, 63, xmlDocument);
	currentSymbolInfo = createSymbolInformation("DOCTYPE:br", SymbolKind.Struct, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 18, 37, xmlDocument);
	currentSymbolInfo = createSymbolInformation("br", SymbolKind.Property, currentLocation, "DOCTYPE:br");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 54, 59, xmlDocument);
	currentSymbolInfo = createSymbolInformation("%all;", SymbolKind.Key, currentLocation, "DOCTYPE:br");
	expectedSymbolInfos.add(currentSymbolInfo);

	currentLocation = createLocation(testURI, 64, 70, xmlDocument);
	currentSymbolInfo = createSymbolInformation("br", SymbolKind.Field, currentLocation, "");
	expectedSymbolInfos.add(currentSymbolInfo);

	assertSymbols(expectedSymbolInfos, actualSymbolInfos);

	settings.setMaxItemsComputed(10);
	initializeTestObjects(xmlText, testURI, settings);
	assertSymbols(expectedSymbolInfos, actualSymbolInfos);

	settings.setMaxItemsComputed(3);
	initializeTestObjects(xmlText, testURI, settings);
	assertSymbols(expectedSymbolInfos.stream().limit(3).collect(Collectors.toList()), actualSymbolInfos);
}
 
源代码27 项目: xtext-core   文件: DocumentSymbolService.java
protected SymbolInformation createSymbol(IEObjectDescription description) {
	String symbolName = getSymbolName(description);
	if (symbolName == null) {
		return null;
	}
	SymbolKind symbolKind = getSymbolKind(description);
	if (symbolKind == null) {
		return null;
	}
	SymbolInformation symbol = new SymbolInformation();
	symbol.setName(symbolName);
	symbol.setKind(symbolKind);
	return symbol;
}
 
源代码28 项目: xtext-core   文件: DocumentSymbolService.java
protected void createSymbol(IEObjectDescription description, IReferenceFinder.IResourceAccess resourceAccess,
		Procedure1<? super SymbolInformation> acceptor) {
	String name = getSymbolName(description);
	if (name == null) {
		return;
	}
	SymbolKind kind = getSymbolKind(description);
	if (kind == null) {
		return;
	}
	getSymbolLocation(description, resourceAccess, (Location location) -> {
		SymbolInformation symbol = new SymbolInformation(name, kind, location);
		acceptor.apply(symbol);
	});
}
 
private List<Either<SymbolInformation, DocumentSymbol>> testRetrieveDocumentSymbol(String textTotest, int expectedSize) throws URISyntaxException, InterruptedException, ExecutionException {
	CamelLanguageServer camelLanguageServer = initializeLanguageServer(textTotest);
	CompletableFuture<List<Either<SymbolInformation,DocumentSymbol>>> documentSymbolFor = getDocumentSymbolFor(camelLanguageServer);
	List<Either<SymbolInformation, DocumentSymbol>> symbolsInformation = documentSymbolFor.get();
	assertThat(symbolsInformation).hasSize(expectedSize);
	return symbolsInformation;
}
 
源代码30 项目: xtext-core   文件: DocumentSymbolService.java
public List<? extends SymbolInformation> getSymbols(IResourceDescription resourceDescription, String query,
		IReferenceFinder.IResourceAccess resourceAccess, CancelIndicator cancelIndicator) {
	List<SymbolInformation> symbols = new LinkedList<>();
	for (IEObjectDescription description : resourceDescription.getExportedObjects()) {
		operationCanceledManager.checkCanceled(cancelIndicator);
		if (filter(description, query)) {
			createSymbol(description, resourceAccess, (SymbolInformation symbol) -> {
				symbols.add(symbol);
			});
		}
	}
	return symbols;
}
 
 类所在包
 同包方法