Skip to content

Commit

Permalink
Merge pull request #445 from onflow/bastian/fix-priv-pub
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent authored Nov 4, 2024
2 parents 7d1f947 + 4443262 commit 9b8e088
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
14 changes: 7 additions & 7 deletions languageserver/server/document_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,20 @@ func TestDocument_HasAnyPrecedingStringsAtPosition(t *testing.T) {

t.Parallel()

doc := Document{Text: " pub \t \n f"}
doc := Document{Text: " access(all) \t \n f"}

assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"pub"}, 2, 1))
assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"pub"}, 2, 2))
assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"pub"}, 2, 3))
assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"access(self)", "pub"}, 2, 2))
assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"access(self)", "pub"}, 1, 6))
assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"access(all)"}, 2, 1))
assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"access(all)"}, 2, 2))
assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"access(all)"}, 2, 3))
assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"access(self)", "access(all)"}, 2, 2))
assert.True(t, doc.HasAnyPrecedingStringsAtPosition([]string{"access(self)", "access(all)"}, 1, 13))
})

t.Run("invalid", func(t *testing.T) {

t.Parallel()

doc := Document{Text: " pub \t \n f"}
doc := Document{Text: " access(all) \t \n f"}

assert.False(t, doc.HasAnyPrecedingStringsAtPosition([]string{"access(self)"}, 2, 2))
})
Expand Down
7 changes: 2 additions & 5 deletions languageserver/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1129,12 +1129,9 @@ var expressionCompletionItems = []*protocol.CompletionItem{
},
}

var allAccessOptions = []string{"pub", "priv", "pub(set)", "access(contract)", "access(account)", "access(self)"}
var allAccessOptions = []string{"access(all)", "access(contract)", "access(account)", "access(self)"}
var allAccessOptionsCommaSeparated = strings.Join(allAccessOptions, ",")

var readAccessOptions = []string{"pub", "priv", "access(contract)", "access(account)", "access(self)"}
var readAccessOptionsCommaSeparated = strings.Join(readAccessOptions, ",")

// NOTE: if the document doesn't specify an access modifier yet,
// the completion item's InsertText will get prefixed with a placeholder
// for the access modifier.
Expand Down Expand Up @@ -1287,7 +1284,7 @@ func (s *Server) Completion(
if requiresAccessModifierPlaceholder {
item = withCompletionItemInsertText(
item,
fmt.Sprintf("${1|%s|} %s", readAccessOptionsCommaSeparated, item.InsertText),
fmt.Sprintf("${1|%s|} %s", allAccessOptionsCommaSeparated, item.InsertText),
)
}
items = append(items, item)
Expand Down

0 comments on commit 9b8e088

Please sign in to comment.