Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for semanticTokens #446

Merged
merged 4 commits into from
Oct 7, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
457 changes: 454 additions & 3 deletions org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/Protocol.xtend

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/**
* Copyright (c) 2016-2018 TypeFox and others.
spoenemann marked this conversation as resolved.
Show resolved Hide resolved
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.lsp4j;

import com.google.common.annotations.Beta;

/**
* @since 3.16.0
*/
@Beta
public final class SemanticTokenModifiers {
private SemanticTokenModifiers() {
}

public static final String Declaration = "declaration";

public static final String Definition = "definition";

public static final String Readonly = "readonly";

public static final String Static = "static";

public static final String Deprecated = "deprecated";

public static final String Abstract = "abstract";

public static final String Async = "async";

public static final String Modification = "modification";

public static final String Documentation = "documentation";

public static final String DefaultLibrary = "defaultLibrary";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**
* Copyright (c) 2016-2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.lsp4j;

import com.google.common.annotations.Beta;

/**
* @since 3.16.0
*/
@Beta
public final class SemanticTokenTypes {
private SemanticTokenTypes() {
}

public static final String Namespace = "namespace";

public static final String Type = "type";

public static final String Class = "class";

public static final String Enum = "enum";

public static final String Interface = "interface";

public static final String Struct = "struct";

public static final String TypeParameter = "typeParameter";

public static final String Parameter = "parameter";

public static final String Variable = "variable";

public static final String Property = "property";

public static final String EnumMember = "enumMember";

public static final String Event = "event";

public static final String Function = "function";

public static final String Member = "member";

public static final String Macro = "macro";

public static final String Keyword = "keyword";

public static final String Modifier = "modifier";

public static final String Comment = "comment";

public static final String String = "string";

public static final String Number = "number";

public static final String Regexp = "regexp";

public static final String Operator = "operator";

}
26 changes: 26 additions & 0 deletions org.eclipse.lsp4j/src/main/java/org/eclipse/lsp4j/TokenFormat.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/**
* Copyright (c) 2016-2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.lsp4j;

import com.google.common.annotations.Beta;

/**
* @since 3.16.0
*/
@Beta
public final class TokenFormat {
private TokenFormat() {
}

public static final String Relative = "relative";

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
/**
* Copyright (c) 2016-2018 TypeFox and others.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0,
* or the Eclipse Distribution License v. 1.0 which is available at
* http://www.eclipse.org/org/documents/edl-v10.php.
*
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
*/
package org.eclipse.lsp4j;

import com.google.common.annotations.Beta;
import java.util.List;
import org.eclipse.lsp4j.jsonrpc.validation.NonNull;
import org.eclipse.lsp4j.util.Preconditions;
import org.eclipse.xtext.xbase.lib.Pure;
import org.eclipse.xtext.xbase.lib.util.ToStringBuilder;

/**
* @since 3.16.0
*/
@Beta
@SuppressWarnings("all")
public class SemanticTokens {
/**
* An optional result id. If provided and clients support delta updating
* the client will include the result id in the next semantic token request.
* A server can then instead of computing all semantic tokens again simply
* send a delta.
*/
private String resultId;

/**
* The actual tokens.
*/
@NonNull
private List<Integer> data;
Copy link
Contributor

@nixel2007 nixel2007 Oct 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for pinging closed PR, but shouldn't we migrate List<Integer> to int[]? It's a huge list/array with a lot of Integer boxing/unboxing operations. Yes, List is more comfortable class with all its Collection methods. But is it fast enough?

@ericdallo @spoenemann WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think it makes sense

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would do some profiling before optimizing something like that. Java ArrayList and Integer boxing/unboxing is super optimized in the JVM, I don't know whether you'll notice any difference for real-world array sizes.


public SemanticTokens(@NonNull final List<Integer> data) {
this.data = Preconditions.<List<Integer>>checkNotNull(data, "data");
}

public SemanticTokens(final String resultId, @NonNull final List<Integer> data) {
this(data);
this.resultId = resultId;
}

/**
* An optional result id. If provided and clients support delta updating
* the client will include the result id in the next semantic token request.
* A server can then instead of computing all semantic tokens again simply
* send a delta.
*/
@Pure
public String getResultId() {
return this.resultId;
}

/**
* An optional result id. If provided and clients support delta updating
* the client will include the result id in the next semantic token request.
* A server can then instead of computing all semantic tokens again simply
* send a delta.
*/
public void setResultId(final String resultId) {
this.resultId = resultId;
}

/**
* The actual tokens.
*/
@Pure
@NonNull
public List<Integer> getData() {
return this.data;
}

/**
* The actual tokens.
*/
public void setData(@NonNull final List<Integer> data) {
this.data = Preconditions.checkNotNull(data, "data");
}

@Override
@Pure
public String toString() {
ToStringBuilder b = new ToStringBuilder(this);
b.add("resultId", this.resultId);
b.add("data", this.data);
return b.toString();
}

@Override
@Pure
public boolean equals(final Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
SemanticTokens other = (SemanticTokens) obj;
if (this.resultId == null) {
if (other.resultId != null)
return false;
} else if (!this.resultId.equals(other.resultId))
return false;
if (this.data == null) {
if (other.data != null)
return false;
} else if (!this.data.equals(other.data))
return false;
return true;
}

@Override
@Pure
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((this.resultId== null) ? 0 : this.resultId.hashCode());
return prime * result + ((this.data== null) ? 0 : this.data.hashCode());
}
}
Loading