Skip to content

Commit

Permalink
Merge pull request #211 from onflow/supun/stable-cadence
Browse files Browse the repository at this point in the history
Update to latest stable cadence
  • Loading branch information
SupunS authored Sep 19, 2023
2 parents cb8a34b + 0f47bd4 commit 1e2b07f
Show file tree
Hide file tree
Showing 28 changed files with 1,817 additions and 526 deletions.
24 changes: 24 additions & 0 deletions .github/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
changelog:
categories:
- title: 💥 Language Breaking Changes
labels:
- Language Breaking Change
- Storage Breaking Change
- title: 💥 Go API Breaking Chance
labels:
- Go API Breaking Change
- title: ⭐ Features
labels:
- Feature
- title: 🛠 Improvements
labels:
- Improvement
- title: 🐞 Bug Fixes
labels:
- Bugfix
- title: 📖 Documentation
labels:
- Documentation
- title: Other Changes
labels:
- "*"
86 changes: 82 additions & 4 deletions languageserver/conversion/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ import (
"github.com/onflow/cadence/runtime/ast"
"github.com/onflow/cadence/runtime/common"
"github.com/onflow/cadence/runtime/sema"
"github.com/onflow/cadence/tools/analysis"

"github.com/onflow/cadence-tools/languageserver/protocol"
)

// ASTToProtocolPosition converts an AST position to a LSP position
//
func ASTToProtocolPosition(pos ast.Position) protocol.Position {
return protocol.Position{
Line: uint32(pos.Line - 1),
Expand All @@ -36,7 +36,6 @@ func ASTToProtocolPosition(pos ast.Position) protocol.Position {
}

// ASTToProtocolRange converts an AST range to a LSP range
//
func ASTToProtocolRange(startPos, endPos ast.Position) protocol.Range {
return protocol.Range{
Start: ASTToProtocolPosition(startPos),
Expand All @@ -45,7 +44,6 @@ func ASTToProtocolRange(startPos, endPos ast.Position) protocol.Range {
}

// ProtocolToSemaPosition converts a LSP position to a sema position
//
func ProtocolToSemaPosition(pos protocol.Position) sema.Position {
return sema.Position{
Line: int(pos.Line + 1),
Expand Down Expand Up @@ -95,7 +93,6 @@ func DeclarationKindToSymbolKind(kind common.DeclarationKind) protocol.SymbolKin
}

// DeclarationToDocumentSymbol converts AST Declaration to a DocumentSymbol
//
func DeclarationToDocumentSymbol(declaration ast.Declaration) protocol.DocumentSymbol {
var children []protocol.DocumentSymbol

Expand Down Expand Up @@ -142,3 +139,84 @@ func DeclarationToDocumentSymbol(declaration ast.Declaration) protocol.DocumentS

return symbol
}

func DeclarationKindToCompletionItemType(kind common.DeclarationKind) protocol.CompletionItemKind {
switch kind {
case common.DeclarationKindFunction:
return protocol.FunctionCompletion

case common.DeclarationKindField:
return protocol.FieldCompletion

case common.DeclarationKindStructure,
common.DeclarationKindResource,
common.DeclarationKindEvent,
common.DeclarationKindContract,
common.DeclarationKindType:
return protocol.ClassCompletion

case common.DeclarationKindStructureInterface,
common.DeclarationKindResourceInterface,
common.DeclarationKindContractInterface:
return protocol.InterfaceCompletion

case common.DeclarationKindVariable:
return protocol.VariableCompletion

case common.DeclarationKindConstant,
common.DeclarationKindParameter:
return protocol.ConstantCompletion

default:
return protocol.TextCompletion
}
}

func SuggestedFixesToCodeActions(
suggestedFixes []analysis.SuggestedFix,
protocolDiagnostic protocol.Diagnostic,
uri protocol.DocumentURI,
) []*protocol.CodeAction {
var codeActions []*protocol.CodeAction
for _, suggestedFix := range suggestedFixes {

codeActionTextEdits := make([]protocol.TextEdit, 0, len(suggestedFix.TextEdits))

for _, suggestedFixTextEdit := range suggestedFix.TextEdits {
var codeActionTextEdit protocol.TextEdit

if len(suggestedFixTextEdit.Insertion) > 0 {
codeActionTextEdit = protocol.TextEdit{
Range: protocol.Range{
Start: ASTToProtocolPosition(suggestedFixTextEdit.StartPos),
End: ASTToProtocolPosition(suggestedFixTextEdit.EndPos),
},
NewText: suggestedFixTextEdit.Insertion,
}
} else {
codeActionTextEdit = protocol.TextEdit{
Range: ASTToProtocolRange(
suggestedFixTextEdit.StartPos,
suggestedFixTextEdit.EndPos,
),
NewText: suggestedFixTextEdit.Replacement,
}
}

codeActionTextEdits = append(codeActionTextEdits, codeActionTextEdit)
}

codeAction := &protocol.CodeAction{
Title: suggestedFix.Message,
Kind: protocol.QuickFix,
Diagnostics: []protocol.Diagnostic{protocolDiagnostic},
Edit: &protocol.WorkspaceEdit{
Changes: map[protocol.DocumentURI][]protocol.TextEdit{
uri: codeActionTextEdits,
},
},
}
codeActions = append(codeActions, codeAction)
}
return codeActions
}
40 changes: 26 additions & 14 deletions languageserver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@ require (
github.com/google/uuid v1.3.0
github.com/mattn/go-isatty v0.0.19
github.com/mitchellh/mapstructure v1.5.0
github.com/onflow/cadence v0.41.0-stable-cadence.1
github.com/onflow/cadence-tools/lint v0.12.0-stable-cadence.1
github.com/onflow/flow-cli/flowkit v1.5.0-stable-cadence.1
github.com/onflow/flow-go-sdk v0.44.0-stable-cadence.1
github.com/onflow/cadence v0.41.0-stable-cadence.1.0.20230918153730-ec4d615b89d8
github.com/onflow/cadence-tools/lint v0.12.0-stable-cadence.1.0.20230918225240-b1fc85f88c80
github.com/onflow/cadence-tools/test v0.12.0-stable-cadence.1.0.20230918225240-b1fc85f88c80
github.com/onflow/flow-cli/flowkit v1.5.0-stable-cadence.1.0.20230919210856-b34bc43b5bc4
github.com/onflow/flow-go-sdk v0.44.0-stable-cadence.1.0.20230915213126-68e7ffb5595f
github.com/sourcegraph/jsonrpc2 v0.1.0
github.com/spf13/afero v1.9.4
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
golang.org/x/exp v0.0.0-20230321023759-10a507213a29
golang.org/x/exp v0.0.0-20230626212559-97b1e661b5df
)

require (
Expand Down Expand Up @@ -48,6 +49,9 @@ require (
github.com/fxamacker/cbor/v2 v2.4.1-0.20230228173756-c0c9f774e40c // indirect
github.com/fxamacker/circlehash v0.3.0 // indirect
github.com/glebarez/go-sqlite v1.21.1 // indirect
github.com/go-kit/kit v0.12.0 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.5.1 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
Expand All @@ -65,6 +69,7 @@ require (
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/golang-lru v0.5.5-0.20210104140557-80c98217689d // indirect
github.com/hashicorp/golang-lru/v2 v2.0.2 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/iancoleman/orderedmap v0.0.0-20190318233801-ac98e3ecb4b0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand All @@ -88,13 +93,17 @@ require (
github.com/klauspost/cpuid/v2 v2.2.5 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-libp2p v0.28.1 // indirect
github.com/libp2p/go-libp2p-pubsub v0.9.3 // indirect
github.com/libp2p/go-msgio v0.3.0 // indirect
github.com/lmars/go-slip10 v0.0.0-20190606092855-400ba44fee12 // indirect
github.com/logrusorgru/aurora v2.0.3+incompatible // indirect
github.com/logrusorgru/aurora/v4 v4.0.0 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
github.com/mitchellh/colorstring v0.0.0-20190213212951-d06e56a500db // indirect
github.com/mr-tron/base58 v1.2.0 // indirect
github.com/multiformats/go-base32 v0.1.0 // indirect
github.com/multiformats/go-base36 v0.2.0 // indirect
Expand All @@ -104,16 +113,17 @@ require (
github.com/multiformats/go-multihash v0.2.3 // indirect
github.com/multiformats/go-multistream v0.4.1 // indirect
github.com/multiformats/go-varint v0.0.7 // indirect
github.com/onflow/atree v0.6.0 // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20230822191436-8a95802475f4 // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20230808220007-f00e74ca675b // indirect
github.com/onflow/flow-emulator v0.55.0-stable-cadence.1 // indirect
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230818200853-ab1b03e98a95 // indirect
github.com/onflow/flow-go v0.31.1-0.20230829185811-090be4adebb5 // indirect
github.com/onflow/atree v0.6.1-0.20230711151834-86040b30171f // indirect
github.com/onflow/flow-core-contracts/lib/go/contracts v1.2.4-0.20230918230627-2daea3d4f44b // indirect
github.com/onflow/flow-core-contracts/lib/go/templates v1.2.4-0.20230918230627-2daea3d4f44b // indirect
github.com/onflow/flow-emulator v0.54.1-0.20230919150501-db4da71c768b // indirect
github.com/onflow/flow-ft/lib/go/contracts v0.7.1-0.20230913160646-09adc7d3b513 // indirect
github.com/onflow/flow-go v0.31.1-0.20230918230928-ba70724dc568 // indirect
github.com/onflow/flow-go/crypto v0.24.9 // indirect
github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20230818200521-3acffe2472a3 // indirect
github.com/onflow/flow-nft/lib/go/contracts v1.1.1-0.20230915224343-ca2663ed82cf // indirect
github.com/onflow/flow/protobuf/go/flow v0.3.2-0.20230628215638-83439d22e0ce // indirect
github.com/onflow/sdks v0.5.0 // indirect
github.com/onflow/sdks v0.5.1-0.20230912225508-b35402f12bba // indirect
github.com/onflow/wal v0.0.0-20230529184820-bc9f8244608d // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/pbnjay/memory v0.0.0-20210728143218-7b4eea64cf58 // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
Expand All @@ -129,6 +139,7 @@ require (
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec // indirect
github.com/rivo/uniseg v0.4.4 // indirect
github.com/rs/zerolog v1.29.0 // indirect
github.com/schollz/progressbar/v3 v3.13.1 // indirect
github.com/sethvargo/go-retry v0.2.3 // indirect
github.com/slok/go-http-metrics v0.10.0 // indirect
github.com/spaolacci/murmur3 v1.1.0 // indirect
Expand Down Expand Up @@ -163,7 +174,8 @@ require (
golang.org/x/net v0.10.0 // indirect
golang.org/x/oauth2 v0.7.0 // indirect
golang.org/x/sync v0.2.0 // indirect
golang.org/x/sys v0.9.0 // indirect
golang.org/x/sys v0.11.0 // indirect
golang.org/x/term v0.9.0 // indirect
golang.org/x/text v0.10.0 // indirect
golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
gonum.org/v1/gonum v0.13.0 // indirect
Expand Down
Loading

0 comments on commit 1e2b07f

Please sign in to comment.