firefly-compiler 0.5.66 → 0.5.68

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.
@@ -49,7 +49,7 @@ handleCompletion(
49
49
  mutable typeCompletions = []
50
50
  let completions = patternCompletions.else {lspHook.results().flatMap {
51
51
  | ResolveTypeHook h =>
52
- typeCompletions = [...typeCompletions, ...typeCompletion(h.types, h.typeGenerics)]
52
+ typeCompletions = [...typeCompletions, ...typeCompletion(h.types, h.typeGenerics, importSymbols)]
53
53
  []
54
54
  | ResolveVariantFieldHook _ =>
55
55
  sawParameterOrVariantFieldHook = True
@@ -259,7 +259,11 @@ importCompletion(moduleKeys: List[ModuleKey]): List[CompletionInfo] {
259
259
  }
260
260
  }
261
261
 
262
- typeCompletion(types: Map[String, String], typeGenerics: Map[String, List[String]]): List[CompletionInfo] {
262
+ typeCompletion(
263
+ types: Map[String, String]
264
+ typeGenerics: Map[String, List[String]]
265
+ importSymbols: ImportSymbolsInfo
266
+ ): List[CompletionInfo] {
263
267
  let completions = types.toList().filter {| Pair(n, full) =>
264
268
  n.all {_.isAsciiLetterOrDigit()}
265
269
  }.map {| Pair(typeName, full) =>
@@ -270,7 +274,11 @@ typeCompletion(types: Map[String, String], typeGenerics: Map[String, List[String
270
274
  let snippet = typeName + if(realGenerics.isEmpty()) {""} else {"[$0]"}
271
275
  CompletionInfo(label, extra, "", snippet, False, TConstructor(Location("", 0, 0), "type", []), full, None)
272
276
  }
273
- completions
277
+ let importCompletions = importSymbols.importSymbols.flatMap {| info =>
278
+ info.typeNames.map: name =>
279
+ makeAutoimportCompletion(info, importSymbols.importLine, name, True)
280
+ }
281
+ [...completions, ...importCompletions]
274
282
  }
275
283
 
276
284
  completion(
@@ -357,34 +365,37 @@ completion(
357
365
  if(prefix == "") {
358
366
  importSymbols.importSymbols.each {| info =>
359
367
  [info.moduleKey.name, ...info.variantNames].distinct().each: name =>
360
- let moduleName = info.moduleKey.folders.map {_ + "."}.join() + info.moduleKey.name
361
- let fromName = if(
362
- info.moduleKey.packagePair.name == "script" && info.moduleKey.packagePair.group == "script"
363
- ) {
364
- ""
365
- } else {
366
- info.moduleKey.packagePair.groupName(":")
367
- }
368
- let importName = if(fromName == "") {moduleName} else {moduleName + " from " + fromName}
369
- // TODO: Add edit that inserts the import
370
- members.push(CompletionInfo(
371
- label = name
372
- extra = ""
373
- more = if(fromName == "") {moduleName} else {fromName + "/" + moduleName}
374
- snippet = name
375
- member = False
376
- type = TConstructor(Location("", 0, 0), "", [])
377
- documentation = "// Will import the following module:\nimport " + importName
378
- expectedType = None
379
- secondarySort = 9
380
- insertion = Some(Pair(importSymbols.importLine, "import " + importName + "\n"))
381
- ))
368
+ members.push(makeAutoimportCompletion(info, importSymbols.importLine, name, False))
382
369
  }
383
370
  }
384
371
 
385
372
  members.toList()
386
373
  }
387
374
 
375
+ makeAutoimportCompletion(info: ImportSymbolInfo, importLine: Int, name: String, isType: Bool): CompletionInfo {
376
+ let moduleName = info.moduleKey.folders.map {_ + "."}.join() + info.moduleKey.name
377
+ let fromName = if(
378
+ info.moduleKey.packagePair.name == "script" && info.moduleKey.packagePair.group == "script"
379
+ ) {
380
+ ""
381
+ } else {
382
+ info.moduleKey.packagePair.groupName(":")
383
+ }
384
+ let importName = if(fromName == "") {moduleName} else {moduleName + " from " + fromName}
385
+ CompletionInfo(
386
+ label = name
387
+ extra = ""
388
+ more = if(fromName == "") {moduleName} else {fromName + "/" + moduleName}
389
+ snippet = name
390
+ member = False
391
+ type = TConstructor(Location("", 0, 0), if(isType) {"type"} else {""}, [])
392
+ documentation = "// Will import the following module:\nimport " + importName
393
+ expectedType = None
394
+ secondarySort = 9
395
+ insertion = Some(Pair(importLine, "import " + importName + "\n"))
396
+ )
397
+ }
398
+
388
399
  makeCompletion(
389
400
  unification: Unification
390
401
  expected: Type
package/lsp/Handler.ff CHANGED
@@ -76,6 +76,7 @@ extend self: Handler {
76
76
  let diagnostics = self.handleFocusDiagnostic(system, parameters, version)
77
77
  [Pair("textDocument/publishDiagnostics", diagnostics)]
78
78
  | "custom/focusDocument" =>
79
+ self.importSymbolsCache = Pair("", [])
79
80
  let diagnostics = self.handleFocusDiagnostic(system, parameters, version)
80
81
  [Pair("textDocument/publishDiagnostics", diagnostics)]
81
82
  | "workspace/didRenameFiles" =>
@@ -240,7 +241,6 @@ extend self: Handler {
240
241
  }*/
241
242
 
242
243
  handleFocusDiagnostic(system: NodeSystem, parameters: Map[String, Json], version: Int): Json {
243
- self.importSymbolsCache = Pair("", [])
244
244
  let js = system.js()
245
245
  let uri = parameters.grab("textDocument").field("uri").grabString()
246
246
  let path = system.pathFromUrl(uri)
@@ -406,7 +406,9 @@ extend self: Handler {
406
406
  errors.each {| CompileError(at, message) =>
407
407
  Log.trace("handleCompletion check error: " + message)
408
408
  }
409
- let importSymbols = self.findModulesToImport(system, path, lspHook)
409
+ let importSymbols = self.printTime(system.mainTask(), "findModulesToImport") {
410
+ self.findModulesToImport(system, path, lspHook)
411
+ }
410
412
  let o = CompletionHandler.handleCompletion(
411
413
  lspHook = lspHook
412
414
  toplevel = completionAt.column == 1
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "description": "Firefly compiler",
5
5
  "author": "Firefly team",
6
6
  "license": "MIT",
7
- "version": "0.5.66",
7
+ "version": "0.5.68",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Ahnfelt/firefly-boot"
@@ -4,7 +4,7 @@
4
4
  "description": "Firefly language support",
5
5
  "author": "Firefly team",
6
6
  "license": "MIT",
7
- "version": "0.5.66",
7
+ "version": "0.5.68",
8
8
  "repository": {
9
9
  "type": "git",
10
10
  "url": "https://github.com/Ahnfelt/firefly-boot"