Skip to content
This repository has been archived by the owner on Jan 9, 2021. It is now read-only.
/ fishy-completion Public archive

A proof-of-concept completion framework for DrRacket via fishy static analysis.

Notifications You must be signed in to change notification settings

sorawee/fishy-completion

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Fishy Completion

This Quickscript script allows users to autocomplete an identifier via static analysis.

To run the script, either use the menu or the keybinding (ctrl , or ctrl < for version 1, and ctrl m for version 2). Running repeatedly will cycle through all candidates (similar to the dynamic completion in Quickscript Extra).

Versions

Fishy completion has two versions: version 1 (script.rkt) and version 2 (script-2.rkt). The latter is supposed to be faster and more expressive.

Following are differences between version 1 and version 2:

  • Version 1 needs expansion twice. Version 2 needs only once, so it is supposed to be faster.
  • Version 1 only supports completion in phase 0 and 1. Version 2 supports every phase.
  • Version 1 under limited scenarios can autocomplete identifiers in syntax template (forms inside quote-syntax / syntax / quasisyntax). Version 2 cannot do that. Arguably, the ability to autocomplete syntax template is undesirable: syntax template is a datum that could be manipulated, so everything is a possible candidate for autocompletion.

Guarantee and limitation

The script guarantees that any autocompleted identifier at a position will definitely be in scope (according to Check Syntax), but it does not guarantee that it will be able to recognize every candidate identifier in the scope. For example, identifiers that are imported from other modules, either explicitly (e.g., via require) or implicitly (e.g., via #lang) are not supported. To autocomplete identifiers from other modules, use the built-in autocomplete feature in DrRacket (ctrl .).

In order to run the completion, the program must not have any compile-time error. However, this is too strict because the fact that you intend to use autocompletion probably means that the current program contains invalid identifiers (and thus compile-time errors). Therefore, errors that are caused by the identifier at the current position (i.e., attempting to use non-identifier macro as an identifier macro) and unbound identifiers are tolerated as special cases. Other errors such as unbalanced parentheses or errors in macro expansion will disable the completion.

As described above, for version 1, the autocompletion only works on code in phase 0 and phase 1. Version 2 doesn't have this restriction, but unbound identifier errors in phase higher than 1 (in different position than the current position) will not be tolerated.

Demo

Demo 1

Fishy completion can be used to autocomplete any identifiers that are defined in a module. Autocompleted identifiers are guaranteed to be in scope.

Demo 2

Fishy completion recognizes non-apparent bindings such as those generated from the struct form. It also recognizes macros. Note that it does not recognize identifiers imported from other modules. Use the built-in autocomplete feature in DrRacket for that case.

Demo 3

Fishy completion can autocomplete quoted identifiers and identifiers that start with a number.

If the current position is not associated with any token that could become an identifier, or if there is no candidate that could be in scope (up to the limitation described above), fishy completion will disable itself.

Demo 4

When there is a compile-time error, fishy completion will disable itself. There are a few exceptions as described above.

Related work

There are several completion framework for Racket.

  • Quickscript Extra's dynamic completion (dynamic-abbrev) autocompletes words using existing words in the current file. Using it to autocomplete an identifier however means that it will suggest invalid identifiers taken from string literals.
  • DrRacket itself has the completion functionality via ctrl .. It does not autocomplete identifiers defined within a module.
  • Racket Mode has its own completion functionality. In addition to supporting identifiers required from other modules, it supports identifiers within a module via Check Syntax (and also other things like autocompleting require). However, it only considers identifiers that appear textually in the code, so identifiers generated programmatically (e.g., from the struct form) are not considered. It does not autocomplete only identifiers that would be in scope.
  • DrComplete enhances the completion functionality in DrRacket significantly. Similar to Racket Mode, it can autocomplete variety of things, including identifiers defined in a module. Additionally, it can discover identifiers generated programmatically. However, similar to Racket Mode, it does not autocomplete only identifiers that would be in scope.

Future work

Default to symbol completion when expansion fails and unrecoverable?

About

A proof-of-concept completion framework for DrRacket via fishy static analysis.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages