firefly-compiler 0.4.19 → 0.4.20

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -66,11 +66,23 @@ data SymbolHook(
66
66
 
67
67
  class Box[T](mutable value: T)
68
68
 
69
+ data DocumentSymbolKind {
70
+ SLet(mutable: Bool)
71
+ SFunction(member: Bool)
72
+ SExtend
73
+ STraitFunction
74
+ STrait
75
+ SInstance
76
+ SVariant
77
+ SType
78
+ SParameter
79
+ }
80
+
69
81
  class ResultHook {
70
82
  ParseSymbolBegin
71
83
  ParseSymbolEnd(
72
84
  name: String
73
- kind: Int
85
+ kind: DocumentSymbolKind
74
86
  selectionStart: Location
75
87
  selectionEnd: Location
76
88
  start: Location
@@ -232,7 +232,7 @@ extend self: Parser {
232
232
  if(self.lspHook.trackSymbols) {
233
233
  self.lspHook.emit(ParseSymbolEnd(
234
234
  name = nameToken.raw()
235
- kind = 14
235
+ kind = SLet(mutable = False)
236
236
  selectionStart = nameToken.at()
237
237
  selectionEnd = nameToken.end()
238
238
  start = nameToken.at()
@@ -254,10 +254,9 @@ extend self: Parser {
254
254
  bestTarget
255
255
  )
256
256
  if(self.lspHook.trackSymbols) {
257
- let kind = if(member) {6} else {12}
258
257
  self.lspHook.emit(ParseSymbolEnd(
259
258
  name = signature.name
260
- kind = kind
259
+ kind = SFunction(member)
261
260
  selectionStart = signature.at
262
261
  selectionEnd = signature.at.Location(column = signature.at.column + signature.name.size())
263
262
  start = signature.at
@@ -365,7 +364,7 @@ extend self: Parser {
365
364
  }
366
365
  self.lspHook.emit(ParseSymbolEnd(
367
366
  name = name
368
- kind = 3 // Namespace
367
+ kind = SExtend
369
368
  selectionStart = nameToken.at()
370
369
  selectionEnd = nameToken.end()
371
370
  start = extendToken.at()
@@ -411,7 +410,7 @@ extend self: Parser {
411
410
  if(self.lspHook.trackSymbols) {
412
411
  self.lspHook.emit(ParseSymbolEnd(
413
412
  name = signatureNameToken.raw()
414
- kind = 12 // Function
413
+ kind = STraitFunction
415
414
  selectionStart = signatureNameToken.at()
416
415
  selectionEnd = signatureNameToken.end()
417
416
  start = signatureNameToken.at()
@@ -436,7 +435,7 @@ extend self: Parser {
436
435
  if(self.lspHook.trackSymbols) {
437
436
  self.lspHook.emit(ParseSymbolEnd(
438
437
  name = nameToken.raw()
439
- kind = 11 // Interface
438
+ kind = STrait
440
439
  selectionStart = nameToken.at()
441
440
  selectionEnd = nameToken.end()
442
441
  start = traitToken.at()
@@ -487,7 +486,7 @@ extend self: Parser {
487
486
  let name = token.raw() + ": " + nameToken.raw()
488
487
  self.lspHook.emit(ParseSymbolEnd(
489
488
  name = name
490
- kind = 19 // Object
489
+ kind = SInstance
491
490
  selectionStart = nameToken.at()
492
491
  selectionEnd = nameToken.end()
493
492
  start = instanceToken.at()
@@ -545,7 +544,7 @@ extend self: Parser {
545
544
  if(self.lspHook.trackSymbols) {
546
545
  self.lspHook.emit(ParseSymbolEnd(
547
546
  name = variantNameToken.raw()
548
- kind = 10 // Enum
547
+ kind = SVariant
549
548
  selectionStart = variantNameToken.at()
550
549
  selectionEnd = variantNameToken.end()
551
550
  start = variantNameToken.at()
@@ -571,7 +570,7 @@ extend self: Parser {
571
570
  if(self.lspHook.trackSymbols) {
572
571
  self.lspHook.emit(ParseSymbolEnd(
573
572
  name = nameToken.raw()
574
- kind = 5
573
+ kind = SType
575
574
  selectionStart = nameToken.at()
576
575
  selectionEnd = nameToken.end()
577
576
  start = kindToken.at()
@@ -770,7 +769,7 @@ extend self: Parser {
770
769
  if(lspTrackSymbols) {
771
770
  self.lspHook.emit(ParseSymbolEnd(
772
771
  name = parameterNameToken.raw()
773
- kind = 7 // Property
772
+ kind = SParameter
774
773
  selectionStart = parameterNameToken.at()
775
774
  selectionEnd = parameterNameToken.end()
776
775
  start = lspFirst.at()
@@ -1059,10 +1058,9 @@ extend self: Parser {
1059
1058
  self.skip(LAssign)
1060
1059
  let value = self.parseTerm()
1061
1060
  if(self.lspHook.trackSymbols) {
1062
- let kind = if(mutable) {13} else {14}
1063
1061
  self.lspHook.emit(ParseSymbolEnd(
1064
1062
  name = nameToken.raw()
1065
- kind = kind
1063
+ kind = SLet(mutable)
1066
1064
  selectionStart = nameToken.at()
1067
1065
  selectionEnd = nameToken.end()
1068
1066
  start = mutableToken.at()
@@ -1095,7 +1093,7 @@ extend self: Parser {
1095
1093
  if(self.lspHook.trackSymbols) {
1096
1094
  self.lspHook.emit(ParseSymbolEnd(
1097
1095
  name = signature.name
1098
- kind = 12
1096
+ kind = SFunction(member = False)
1099
1097
  selectionStart = signature.at
1100
1098
  selectionEnd = signature.at.Location(column = signature.at.column + signature.name.size())
1101
1099
  start = functionAt
package/core/Json.ff CHANGED
@@ -405,8 +405,8 @@ internalCompare(a: Json, b: Json): Int
405
405
  } else if (typeof a_ === 'number' || typeof b_ === 'number') {
406
406
  if(typeof b_ !== 'number') return -1;
407
407
  if(typeof a_ !== 'number') return 1;
408
- if(isNaB(a_)) return isNaB(b_) ? 0 : -1;
409
- if(isNaB(b_)) return 1;
408
+ if(isNaN(a_)) return isNaN(b_) ? 0 : -1;
409
+ if(isNaN(b_)) return 1;
410
410
  return a_ < b_ ? -1 : 1;
411
411
  } else if (typeof a_ === 'string' || typeof b_ === 'string') {
412
412
  if(typeof b_ !== 'string') return -1;
@@ -748,8 +748,8 @@ toplevelCompletion(lspHook: LspHook): List[CompletionInfo] {
748
748
  label = "webapp",
749
749
  extra = " with frontend and backend",
750
750
  snippet = [
751
- "dependency ff:httpserver:0.0.0"
752
- "import HttpServer from ff:httpserver"
751
+ "dependency ff:webserver:0.0.0"
752
+ "import WebServer from ff:webserver"
753
753
  ""
754
754
  "browserMain(system: BrowserSystem): Unit {"
755
755
  " let response = system.httpClient().fetch(\"http://localhost:8080/hello\")"
@@ -758,19 +758,19 @@ toplevelCompletion(lspHook: LspHook): List[CompletionInfo] {
758
758
  "}"
759
759
  ""
760
760
  "nodeMain(system: NodeSystem): Unit {"
761
- " HttpServer.listen(system, \"localhost\", 8080) {request, response =>"
762
- " if(request.path() == \"/\") {"
763
- " response.setHeader(\"Content-Type\", [\"text/html; charset=UTF-8\"])"
764
- " response.writeText(\"<!doctype html>\")"
765
- " response.writeText(\"<script type='module' src='/js/script/script/WebApp.mjs'></script>\")"
766
- " } elseIf {request.path() == \"/hello\"} {"
767
- " response.setHeader(\"Content-Type\", [\"text/plain; charset=UTF-8\"])"
768
- " response.writeText(\"Hello from server!\")"
769
- " } elseIf {request.path().startsWith(\"/js/\") && !request.path().contains(\"..\")} {"
770
- " response.setHeader(\"Content-Type\", [\"text/javascript; charset=UTF-8\"])"
771
- " response.writeText(system.assets().readText(request.path()))"
761
+ " WebServer.make(system, \"localhost\", 8080).listen {request =>"
762
+ " if(request.readPath() == \"/\") {"
763
+ " request.writeHeader(\"Content-Type\", \"text/html; charset=UTF-8\")"
764
+ " request.writeText(\"<!doctype html>\")"
765
+ " request.writeText(\"<script type='module' src='/js/script/script/WebApp.mjs'></script>\")"
766
+ " } elseIf {request.readPath() == \"/hello\"} {"
767
+ " request.writeHeader(\"Content-Type\", \"text/plain; charset=UTF-8\")"
768
+ " request.writeText(\"Hello from server!\")"
769
+ " } elseIf {request.readPath().startsWith(\"/js/\") && !request.readPath().contains(\"..\")} {"
770
+ " request.writeHeader(\"Content-Type\", \"text/javascript; charset=UTF-8\")"
771
+ " request.writeText(system.assets().readText(request.readPath()))"
772
772
  " } else {"
773
- " response.writeStatus(404, Some(\"Not found\"))"
773
+ " request.writeStatus(\"404 Not found\")"
774
774
  " }"
775
775
  " }"
776
776
  "}"
package/lsp/Handler.ff CHANGED
@@ -280,7 +280,7 @@ extend self: Handler {
280
280
  let documentSymbols = self.getDocumentSymbolsWithCache(system, file)
281
281
  let workspaceSymbols = documentSymbols.flatMap {SymbolHandler.documentToWorkspaceSymbols(_, None)}
282
282
  if(query == "") {
283
- workspaceSymbols.filter {_.kind == 5} // Class
283
+ workspaceSymbols.filter {_.kind == SType}
284
284
  } else {
285
285
  workspaceSymbols.filter {SymbolHandler.symbolFilter(_, query)}
286
286
  }
@@ -3,7 +3,7 @@ import Syntax from ff:compiler
3
3
 
4
4
  data DocumentSymbol(
5
5
  name: String
6
- kind: Int
6
+ kind: DocumentSymbolKind
7
7
  selectionStart: Location
8
8
  selectionEnd: Location
9
9
  start: Location
@@ -13,7 +13,7 @@ data DocumentSymbol(
13
13
 
14
14
  data WorkspaceSymbol(
15
15
  name: String
16
- kind: Int
16
+ kind: DocumentSymbolKind
17
17
  containerName: Option[String]
18
18
  selectionStart: Location
19
19
  selectionEnd: Location
@@ -93,16 +93,30 @@ showPosition(at: Location): String {
93
93
  documentSymbolToLsp(symbol: DocumentSymbol): Json {
94
94
  Json.object()
95
95
  .with("name", symbol.name)
96
- .with("kind", symbol.kind)
96
+ .with("kind", documentSymbolNumber(symbol.kind))
97
97
  .with("range", locationsToLspRange(symbol.start, symbol.end))
98
98
  .with("selectionRange", locationsToLspRange(symbol.selectionStart, symbol.selectionEnd))
99
99
  .with("children", symbol.children.map {documentSymbolToLsp(_)})
100
100
  }
101
101
 
102
+ documentSymbolNumber(kind: DocumentSymbolKind): Int {
103
+ | SExtend => 3 // Namespace
104
+ | SFunction(True) => 6
105
+ | SFunction(False) => 12
106
+ | SInstance => 19 // Object
107
+ | SLet(True) => 13
108
+ | SLet(False) => 14
109
+ | SParameter => 7 // Property
110
+ | STrait => 11 // Interface
111
+ | STraitFunction => 12 // Function
112
+ | SType => 5
113
+ | SVariant => 10 // Enum
114
+ }
115
+
102
116
  workspaceSymbolToLsp(rootPath: Path, symbol: WorkspaceSymbol): Json {
103
117
  let o = Json.object()
104
118
  .with("name", symbol.name)
105
- .with("kind", symbol.kind)
119
+ .with("kind", documentSymbolNumber(symbol.kind))
106
120
  .with("location", Json.object()
107
121
  .with("uri", rootPath.path(symbol.selectionStart.file).url())
108
122
  .with("range", locationsToLspRange(symbol.selectionStart, symbol.selectionEnd))