Skip to content

Commit

Permalink
Merge pull request #56 from smithy-lang/main
Browse files Browse the repository at this point in the history
Update dss with upstream aws main branch changes
  • Loading branch information
lewisjkl authored Oct 18, 2024
2 parents 5f67586 + b425716 commit a6fde63
Show file tree
Hide file tree
Showing 48 changed files with 1,879 additions and 1,212 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Smithy Language Server Changelog

## 0.4.1 (2024-09-09)

### Features
* Added support for multiple workspaces. ([#160](https://github.com/smithy-lang/smithy-language-server/pull/160))

### Bug fixes
* Fixed file patterns for `didChangeWatchedFiles` on Windows. ([#160](https://github.com/smithy-lang/smithy-language-server/pull/160))

## 0.4.0 (2024-07-30)

### Breaking
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.4.0
0.4.1
300 changes: 157 additions & 143 deletions src/main/java/software/amazon/smithy/lsp/SmithyLanguageServer.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,12 @@

package software.amazon.smithy.lsp.codeactions;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.lsp4j.CodeAction;
import org.eclipse.lsp4j.Position;
import org.eclipse.lsp4j.Range;
import org.eclipse.lsp4j.TextEdit;
import org.eclipse.lsp4j.WorkspaceEdit;
import software.amazon.smithy.lsp.protocol.LspAdapter;

public final class DefineVersionCodeAction {
private static final int DEFAULT_VERSION = 1;
Expand All @@ -42,10 +40,9 @@ public static CodeAction build(String fileUri) {
codeAction.setKind(SmithyCodeActions.SMITHY_DEFINE_VERSION);
WorkspaceEdit wEdit = new WorkspaceEdit();
TextEdit edit = new TextEdit(
new Range(new Position(0, 0), new Position(0, 0)),
"$version: \"" + DEFAULT_VERSION + "\"\n\n"
);
Map<String, List<TextEdit>> changes = Collections.singletonMap(fileUri, Collections.singletonList(edit));
LspAdapter.origin(),
String.format("$version: \"%s\"%n%n", DEFAULT_VERSION));
Map<String, List<TextEdit>> changes = Map.of(fileUri, List.of(edit));
wEdit.setChanges(changes);
codeAction.setEdit(wEdit);
return codeAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,8 @@ public static List<CodeAction> versionCodeActions(CodeActionParams params) {
}
Optional<Diagnostic> updateVersionDiagnostic = params.getContext().getDiagnostics().stream()
.filter(diagnosticCodePredicate(SmithyDiagnostics.UPDATE_VERSION)).findFirst();
if (updateVersionDiagnostic.isPresent()) {
actions.add(
UpdateVersionCodeAction.build(fileUri, updateVersionDiagnostic.get().getRange())
);
}
updateVersionDiagnostic.ifPresent(diagnostic -> actions.add(
UpdateVersionCodeAction.build(fileUri, diagnostic.getRange())));

return actions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

package software.amazon.smithy.lsp.codeactions;

import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.eclipse.lsp4j.CodeAction;
Expand All @@ -41,7 +40,7 @@ public static CodeAction build(String fileUri, Range versionStatementRange) {
codeAction.setKind(SmithyCodeActions.SMITHY_UPDATE_VERSION);
WorkspaceEdit wEdit = new WorkspaceEdit();
TextEdit edit = new TextEdit(versionStatementRange, "$version: \"" + LATEST_VERSION + "\"");
Map<String, List<TextEdit>> changes = Collections.singletonMap(fileUri, Collections.singletonList(edit));
Map<String, List<TextEdit>> changes = Map.of(fileUri, List.of(edit));
wEdit.setChanges(changes);
codeAction.setEdit(wEdit);
return codeAction;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ public CharBuffer borrowId(Position position) {
if (id == null) {
return null;
}
return id.borrowIdValue();
return id.idSlice();
}

/**
Expand Down
32 changes: 7 additions & 25 deletions src/main/java/software/amazon/smithy/lsp/document/DocumentId.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@
* An inaccurate representation of an identifier within a model. It is
* inaccurate in the sense that the string value it references isn't
* necessarily a valid identifier, it just looks like an identifier.
*
* @param type The type of the id
* @param idSlice A borrowed slice containing the id's value
* @param range The range the id occupies
*/
public final class DocumentId {
public record DocumentId(Type type, CharBuffer idSlice, Range range) {
/**
* Represents the different kinds of identifiers that can be used to match.
*/
Expand Down Expand Up @@ -41,32 +45,10 @@ public enum Type {
/**
* Same as {@link Type#ID}, but with a member - will have a {@code $}.
*/
RELATIVE_WITH_MEMBER;
}

private final Type type;
private final CharBuffer buffer;
private final Range range;

DocumentId(Type type, CharBuffer buffer, Range range) {
this.type = type;
this.buffer = buffer;
this.range = range;
}

public Type type() {
return type;
RELATIVE_WITH_MEMBER
}

public String copyIdValue() {
return buffer.toString();
}

public CharBuffer borrowIdValue() {
return buffer;
}

public Range range() {
return range;
return idSlice.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,8 @@

/**
* The imports of a document, including the range they occupy.
*
* @param importsRange The range of the imports
* @param imports The set of imported shape ids. They are not guaranteed to be valid shape ids
*/
public final class DocumentImports {
private final Range importsRange;
private final Set<String> imports;

DocumentImports(Range importsRange, Set<String> imports) {
this.importsRange = importsRange;
this.imports = imports;
}

/**
* @return The range of the imports
*/
public Range importsRange() {
return importsRange;
}

/**
* @return The set of imported shape ids. They are not guaranteed
* to be valid shape ids
*/
public Set<String> imports() {
return imports;
}
}
public record DocumentImports(Range importsRange, Set<String> imports) {}
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,8 @@

/**
* The namespace of the document, including the range it occupies.
*
* @param statementRange The range of the statement, including {@code namespace}
* @param namespace The namespace of the document. Not guaranteed to be a valid namespace
*/
public final class DocumentNamespace {
private final Range statementRange;
private final CharSequence namespace;

DocumentNamespace(Range statementRange, CharSequence namespace) {
this.statementRange = statementRange;
this.namespace = namespace;
}

/**
* @return The range of the statement, including {@code namespace}
*/
public Range statementRange() {
return statementRange;
}

/**
* @return The namespace of the document. Not guaranteed to be
* a valid namespace
*/
public CharSequence namespace() {
return namespace;
}
}
public record DocumentNamespace(Range statementRange, CharSequence namespace) {}
Original file line number Diff line number Diff line change
Expand Up @@ -156,31 +156,23 @@ public Map<Position, DocumentShape> documentShapes(Set<Shape> shapes) {
continue;
}

DocumentShape documentShape;
if (shape.isMemberShape()) {
DocumentShape.Kind kind = DocumentShape.Kind.DefinedMember;
if (is('$')) {
kind = DocumentShape.Kind.Elided;
}
DocumentShape member = documentShape(kind);
documentShapes.put(member.range().getStart(), member);
sp();
if (peek() == ':') {
skip();
// get target
sp();
DocumentShape target = documentShape(DocumentShape.Kind.Targeted);
documentShapes.put(target.range().getStart(), target);
member.setTargetReference(target);
}
documentShape = documentShape(kind);
} else {
skipAlpha(); // shape type
sp();
DocumentShape shapeDef = documentShape(DocumentShape.Kind.DefinedShape);
if (shapeDef.shapeName().length() == 0) {
// Not sure if we should set the shape name here
shapeDef.setKind(DocumentShape.Kind.Inline);
}
documentShapes.put(shapeDef.range().getStart(), shapeDef);
documentShape = documentShape(DocumentShape.Kind.DefinedShape);
}

documentShapes.put(documentShape.range().getStart(), documentShape);
if (documentShape.hasMemberTarget()) {
DocumentShape memberTarget = documentShape.targetReference();
documentShapes.put(memberTarget.range().getStart(), memberTarget);
}
}
return documentShapes;
Expand All @@ -198,7 +190,21 @@ private DocumentShape documentShape(DocumentShape.Kind kind) {
int endIdx = position();
Range range = new Range(start, end);
CharSequence shapeName = document.borrowSpan(startIdx, endIdx);
return new DocumentShape(range, shapeName, kind);

// This is a bit ugly, but it avoids intermediate allocations (like a builder would require)
DocumentShape targetReference = null;
if (kind == DocumentShape.Kind.DefinedMember) {
sp();
if (is(':')) {
skip();
sp();
targetReference = documentShape(DocumentShape.Kind.Targeted);
}
} else if (kind == DocumentShape.Kind.DefinedShape && (shapeName == null || shapeName.isEmpty())) {
kind = DocumentShape.Kind.Inline;
}

return new DocumentShape(range, shapeName, kind, targetReference);
}

/**
Expand Down Expand Up @@ -604,15 +610,10 @@ private boolean isSp() {

private boolean isWs(int offset) {
char peeked = peek(offset);
switch (peeked) {
case '\n':
case '\r':
case ' ':
case '\t':
return true;
default:
return false;
}
return switch (peeked) {
case '\n', '\r', ' ', '\t' -> true;
default -> false;
};
}

private boolean isEof() {
Expand Down Expand Up @@ -643,33 +644,12 @@ private boolean isShapeType() {
return false;
}

switch (token.toString()) {
case "structure":
case "operation":
case "string":
case "integer":
case "list":
case "map":
case "boolean":
case "enum":
case "union":
case "blob":
case "byte":
case "short":
case "long":
case "float":
case "double":
case "timestamp":
case "intEnum":
case "document":
case "service":
case "resource":
case "bigDecimal":
case "bigInteger":
return true;
default:
return false;
}
return switch (token.toString()) {
case "structure", "operation", "string", "integer", "list", "map", "boolean", "enum", "union", "blob",
"byte", "short", "long", "float", "double", "timestamp", "intEnum", "document", "service",
"resource", "bigDecimal", "bigInteger" -> true;
default -> false;
};
}

private int firstIndexOfWithOnlyLeadingWs(String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,5 @@ public enum DocumentPositionContext {
/**
* An unknown or indeterminate position.
*/
OTHER;
OTHER
}
Loading

0 comments on commit a6fde63

Please sign in to comment.