Skip to content
This repository was archived by the owner on Aug 13, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public final class CompletionEntryDetails {
private ImmutableList<ScriptElementKindModifier> kindModifiers;
private ImmutableList<SymbolDisplayPart> displayParts;
private ImmutableList<SymbolDisplayPart> documentation;
private ImmutableList<JSDocTagInfo> tags;

public CompletionEntryDetails(
@JsonProperty("name") String name,
@JsonProperty("kind") ScriptElementKind kind,
@JsonProperty("kindModifiers") String kindModifiers,
@JsonProperty("displayParts") List<SymbolDisplayPart> displayParts,
@JsonProperty("documentation") List<SymbolDisplayPart> documentation) {
@JsonProperty("documentation") List<SymbolDisplayPart> documentation,
@JsonProperty("tags") List<JSDocTagInfo> tags) {
checkNotNull(name);
checkNotNull(kind);
checkNotNull(kindModifiers);
Expand All @@ -52,6 +54,7 @@ public CompletionEntryDetails(
this.kindModifiers = ScriptElementKindModifier.parseList(kindModifiers);
this.displayParts = ImmutableList.copyOf(displayParts);
this.documentation = ImmutableList.copyOf(documentation);
this.tags = ImmutableList.copyOf(tags);
}

public String getName() {
Expand All @@ -74,6 +77,10 @@ public String getDocumentation() {
return SymbolDisplayPart.getText(this.documentation);
}

public String getTags() {
return JSDocTagInfo.getText(this.tags);
}

@Override
public String toString() {
return Objects.toStringHelper(this)
Expand All @@ -82,6 +89,7 @@ public String toString() {
.add("kindModifiers", this.kindModifiers)
.add("displayParts", this.displayParts)
.add("documentation", this.documentation)
.add("tags", this.tags)
.toString();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright 2017 Palantir Technologies, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.palantir.typescript.services.language;

import static com.google.common.base.Preconditions.checkNotNull;

import java.util.List;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Objects;
import com.google.common.base.StandardSystemProperty;

/**
* Corresponds to the class with the same name in TypeScript.
*
* @author Rouche
*/
public final class JSDocTagInfo {

private final String name;
private final String text;

public JSDocTagInfo(
@JsonProperty("name") String name,
@JsonProperty("text") String text) {
checkNotNull(name);

this.name = name;
this.text = text;
}

public String getName() {
return this.name;
}

public String getText() {
return this.text;
}

@Override
public String toString() {
return Objects.toStringHelper(this)
.add("name", this.name)
.add("text", this.text)
.toString();
}

public static String getText(List<JSDocTagInfo> parts) {
checkNotNull(parts);

StringBuilder displayText = new StringBuilder();

for (JSDocTagInfo part : parts) {
displayText.append(part.getName());
if(part.getText() != null && part.getText().trim().length() > 0) {
displayText.append(" ");
displayText.append(part.getText());
}
displayText.append(StandardSystemProperty.LINE_SEPARATOR.value());
}

return displayText.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ public final class QuickInfo {
private final TextSpan textSpan;
private final ImmutableList<SymbolDisplayPart> displayParts;
private final ImmutableList<SymbolDisplayPart> documentation;
private final ImmutableList<JSDocTagInfo> tags;

public QuickInfo(
@JsonProperty("kind") ScriptElementKind kind,
@JsonProperty("kindModifiers") String kindModifiers,
@JsonProperty("textSpan") TextSpan textSpan,
@JsonProperty("displayParts") List<SymbolDisplayPart> displayParts,
@JsonProperty("documentation") List<SymbolDisplayPart> documentation) {
@JsonProperty("documentation") List<SymbolDisplayPart> documentation,
@JsonProperty("tags") List<JSDocTagInfo> tags) {
checkNotNull(kind);
checkNotNull(kindModifiers);
checkNotNull(textSpan);
Expand All @@ -53,6 +55,7 @@ public QuickInfo(
this.textSpan = textSpan;
this.displayParts = ImmutableList.copyOf(displayParts);
this.documentation = documentation != null ? ImmutableList.copyOf(documentation) : ImmutableList.<SymbolDisplayPart> of();
this.tags = ImmutableList.copyOf(tags);
}

public ScriptElementKind getKind() {
Expand All @@ -79,6 +82,14 @@ public List<SymbolDisplayPart> getDocumentation() {
return this.documentation;
}

public List<JSDocTagInfo> getTags() {
return this.tags;
}

public String getTagsText() {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

never use?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I was unsure if you want to add the text in the Over. At least the method is there.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

by "Over" you mean "Overview"?

@Rouche Rouche Jan 11, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Oops... i mean the Hover lol. The popup that appear on Hovering. This method would have to be used to fill it with more info.

Sorry.

return JSDocTagInfo.getText(this.tags);
}

public String getDocumentationText() {
return SymbolDisplayPart.getText(this.documentation);
}
Expand All @@ -91,6 +102,7 @@ public String toString() {
.add("textSpan", this.textSpan)
.add("displayParts", this.displayParts)
.add("documentation", this.documentation)
.add("tags", this.tags)
.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.eclipse.swt.graphics.Image;

import com.google.common.base.CharMatcher;
import com.google.common.base.StandardSystemProperty;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import com.palantir.typescript.Images;
Expand Down Expand Up @@ -112,9 +113,8 @@ public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int
Image image = Images.getImage(entry.getKind(), entry.getKindModifiers());
String displayString = entry.getName() + " " + entry.getDisplayParts();
IContextInformation contextInformation = null;
String additionalProposalInfo = entry.getDocumentation();
CompletionProposal proposal = new CompletionProposal(replacementString, replacementOffset, replacementLength,
cursorPosition, image, displayString, contextInformation, additionalProposalInfo);
cursorPosition, image, displayString, contextInformation, getAdditionalInfo(entry));

proposals.add(proposal);
}
Expand Down Expand Up @@ -159,6 +159,17 @@ public String getErrorMessage() {
public void selectionChanged(ICompletionProposal proposal, boolean smartToggle) {
}

private String getAdditionalInfo(CompletionEntryDetails entry) {

StringBuilder info = new StringBuilder(entry.getDocumentation());
if(info.length() > 0) {
info.append(StandardSystemProperty.LINE_SEPARATOR.value());
}
info.append(entry.getTags());

return info.toString();
}

private int getOffset(int offset) {
if (this.currentCompletionInfo != null) {
boolean memberCompletion = this.currentCompletionInfo.isMemberCompletion();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,17 +118,22 @@ public IPresentationRepairer getRepairer(String contentType) {
*/
private void processEvent(TextEvent event) {
IRegion damagedRegion = this.getDamagedRegion(event);
EndOfLineState lastDamagedLexState = this.updateFinalLexStates(event, damagedRegion);
TextPresentation presentation = this.createPresentation(damagedRegion, lastDamagedLexState);
if(damagedRegion != null) {
EndOfLineState lastDamagedLexState = this.updateFinalLexStates(event, damagedRegion);
TextPresentation presentation = this.createPresentation(damagedRegion, lastDamagedLexState);

this.viewer.changeTextPresentation(presentation, false);
this.viewer.changeTextPresentation(presentation, false);
}
}

/**
* Gets the damaged region by selecting the whole lines touched by the text edit.
*/
private IRegion getDamagedRegion(TextEvent event) {
IDocument document = this.viewer.getDocument();
if(document == null) {
return null;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

minor preference on using optional instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Gonna have to fill me in on this one. Been in TypeScript last year rusted my reflexes :P

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

something like

if (document == null) {
    return Optional.absent();
}

it's preferred so that the caller would know that the value might not be present, so it can do

if (maybeDamagedRegion.isPresent()) {
    IRegion damagedRegion = this.getDamagedRegion(event).get();
    ...
}

it doesnt seem like anywhere else is using this pattern though so fine to keep it as it is for code consistency too

@Rouche Rouche Jan 12, 2017

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ok i see.

Well, you know Optional is JDK 1.8, the plugin right now is still JDK 1.6, until i commit my update of Tycko to 0.26.0, wich is pending on this merge :) This one is a lot more important.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

guava's be fine (thats what everyone uses before JDK 1.8), but yea not really important :P

}
int documentLength = document.getLength();
int offset = event.getOffset();
int length = event.getLength();
Expand Down