Skip to content

Commit

Permalink
SourceRange -> Range; fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
StachuDotNet committed Apr 30, 2024
1 parent c9e60aa commit 27b8fef
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 196 deletions.
4 changes: 2 additions & 2 deletions backend/src/BuiltinExecution/Libs/Parser.fs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ let fns : List<BuiltInFn> =
let startPos = cursor.Current.StartPosition
let endPos = cursor.Current.EndPosition

let sourceRange =
let range =
let fields = [ "start", mapPoint startPos; "end_", mapPoint endPos ]
DRecord(rangeTypeName, rangeTypeName, [], Map fields)

Expand Down Expand Up @@ -91,7 +91,7 @@ let fns : List<BuiltInFn> =
[ ("fieldName", fieldName)
("typ", DString cursor.Current.Kind)
("text", DString sourceText)
("range", sourceRange)
("range", range)
("children", DList(VT.customType parsedNodeTypeName [], children)) ]

DRecord(parsedNodeTypeName, parsedNodeTypeName, [], Map fields)
Expand Down
1 change: 0 additions & 1 deletion backend/src/LibParser/Canvas.fs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,6 @@ let parse
None // whole file

let moduleWT = parseDecls owner canvasName decls
debuG "Parsed module" moduleWT

// Initial pass, so we can re-parse with all names in context
let! result = toPT builtins pm onMissing moduleWT
Expand Down
1 change: 0 additions & 1 deletion backend/src/LibParser/WrittenTypesToProgramTypes.fs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ module Expr =
| WT.EBool(id, b) -> return PT.EBool(id, b)
| WT.EUnit id -> return PT.EUnit id
| WT.EVariable(id, var) ->
if var = "format" then debuG "format" (currentModule)
// This could be a UserConstant
let! constant =
NR.resolveConstantName
Expand Down
2 changes: 1 addition & 1 deletion backend/src/LocalExec/LoadPackagesFromDisk.fs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let load (builtins : RT.Builtins) : Ply<PT.Packages> =
filesWithContents
// TODO: parallelize
|> Ply.List.mapSequentially (fun (path, contents) ->
//debuG "parsing" path
debuG "parsing" path
LibParser.Parser.parsePackageFile
builtins
RT.PackageManager.empty
Expand Down
16 changes: 7 additions & 9 deletions packages/darklang/languageTools/lsp-server/semanticTokens.dark
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ module Darklang =
: List<LanguageServerProtocol.SemanticTokens.RelativeSemanticToken.RelativeSemanticToken<LanguageTools.SemanticTokens.TokenType>> =
tokens
|> Stdlib.List.sortByComparator_v0 (fun a b ->
let aStart = a.sourceRange.start
let bStart = b.sourceRange.start
let aStart = a.range.start
let bStart = b.range.start

if Stdlib.Int64.lessThan aStart.row bStart.row then
-1L
Expand All @@ -81,28 +81,26 @@ module Darklang =
let (tokensSoFar, startOfLastToken) = acc

let (deltaLine, deltaStart) =
match token.sourceRange.start.row - startOfLastToken.row with
| 0L ->
(0UL, token.sourceRange.start.column - startOfLastToken.column)
match token.range.start.row - startOfLastToken.row with
| 0L -> (0UL, token.range.start.column - startOfLastToken.column)
| lineDiff ->
let lineDiff =
lineDiff |> Stdlib.UInt64.fromInt64 |> Builtin.unwrap

(lineDiff, token.sourceRange.start.column)
(lineDiff, token.range.start.column)

let newToken =
LanguageServerProtocol.SemanticTokens.RelativeSemanticToken.RelativeSemanticToken //<LanguageTools.SemanticTokens.TokenType>
{ deltaLine = deltaLine
deltaStart =
deltaStart |> Stdlib.UInt64.fromInt64 |> Builtin.unwrap
length =
(token.sourceRange.end_.column
- token.sourceRange.start.column)
(token.range.end_.column - token.range.start.column)
|> Stdlib.UInt64.fromInt64
|> Builtin.unwrap
tokenType = token.tokenType }

(Stdlib.List.push tokensSoFar newToken, token.sourceRange.start)))
(Stdlib.List.push tokensSoFar newToken, token.range.start)))
|> Stdlib.Tuple2.first
|> Stdlib.List.reverse

Expand Down
10 changes: 3 additions & 7 deletions packages/darklang/languageTools/parser/identifiers.dark
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@ module Darklang =
module Identifiers =
let extractModuleIdentifiersHelper
(modulesSoFarInReverse:
List<WrittenTypes.ModuleIdentifier * WrittenTypes.SourceRange>)
List<WrittenTypes.ModuleIdentifier * WrittenTypes.Range>)
(nodes: List<ParsedNode>)
: (List<WrittenTypes.ModuleIdentifier * WrittenTypes.SourceRange> *
ParsedNode)
=
: (List<WrittenTypes.ModuleIdentifier * WrittenTypes.Range> * ParsedNode) =
match nodes with
| modulePart :: symbolPart :: otherParts ->
if modulePart.typ != "module_identifier" then
Expand Down Expand Up @@ -38,9 +36,7 @@ module Darklang =
/// ensuring that we take note of the `.` source ranges after each module name
let extractModuleIdentifiers
(nodes: List<ParsedNode>)
: (List<WrittenTypes.ModuleIdentifier * WrittenTypes.SourceRange> *
ParsedNode)
=
: (List<WrittenTypes.ModuleIdentifier * WrittenTypes.Range> * ParsedNode) =
let (modulesInReverse, lastNode) = extractModuleIdentifiersHelper [] nodes
(Stdlib.List.reverse modulesInReverse, lastNode)

Expand Down
4 changes: 2 additions & 2 deletions packages/darklang/languageTools/parser/typeDeclaration.dark
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ module Darklang =

| [ fieldNode; separator ] ->
(parseRecordField fieldNode,
Stdlib.Option.Option.Some separator.sourceRange)
Stdlib.Option.Option.Some separator.range)
| _ ->
(createUnparseableError chunk,
Stdlib.Option.Option.Some separator.sourceRange))
Stdlib.Option.Option.Some separator.range))

| None -> (Stdlib.Result.Result.Ok [], Stdlib.Option.Option.None)

Expand Down
14 changes: 6 additions & 8 deletions packages/darklang/languageTools/semanticTokens.dark
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Darklang =
module LanguageTools =
module SemanticTokens =
// <aliases>
type SourceRange = Parser.Range
type Range = Parser.Range
// <aliases>

type TokenType =
Expand Down Expand Up @@ -46,12 +46,10 @@ module Darklang =
///
/// These tokens mean little without reference to a document where the
/// 'ranges' live within.
type SemanticToken =
{ sourceRange: SourceRange
tokenType: TokenType }
type SemanticToken = { range: Range; tokenType: TokenType }

let makeToken (s: SourceRange) (t: TokenType) : SemanticToken =
SemanticToken { sourceRange = s; tokenType = t }
let makeToken (s: Range) (t: TokenType) : SemanticToken =
SemanticToken { range = s; tokenType = t }


module ModuleIdentifier =
Expand Down Expand Up @@ -406,13 +404,13 @@ module Darklang =
fields
|> Stdlib.List.map (fun (symbol, fieldName, value) ->
// TODO: use tuple destructuring, once nested tuple destructuring in a lambda is fixed
// i.e. fun (symbol, (sourceRange, _), value) -> ... instead of the below code
// i.e. fun (symbol, (range, _), value) -> ... instead of the below code
let (range, _) = fieldName

[ // name
[ makeToken range TokenType.Property ]
// =
[ makeToken symbol.sourceRange TokenType.Symbol ]
[ makeToken symbol.range TokenType.Symbol ]
// "Alice"
Expr.tokenize value ])
|> Stdlib.List.flatten
Expand Down
Loading

0 comments on commit 27b8fef

Please sign in to comment.