rescript-vscode icon indicating copy to clipboard operation
rescript-vscode copied to clipboard

Added the command of overwriting interface files

Open QingyaoLin opened this issue 3 years ago • 4 comments

Added the command of overwriting interface files

I need to update the .resi interface file from time to time while using the plugin. However, in each operation, I had to delete the old file before using the plug-in command to create a new .resi interface file, which was really uncomfortable. Therefore, I have the following improvement requirements.

  1. When a .resi file exists, the command can override the contents of the original file.
  2. If the file does not exist, the .resi file is created, and the behavior is the same as that of creating an interface file.

In terms of implementation

I looked at the source code, and adding a command doesn't add much complexity.

Other things

I am very sorry that I have not learned the TS code, so I cannot submit the relevant code implementation. Thank you very much for your earnest and dedication.

QingyaoLin avatar Dec 09 '22 07:12 QingyaoLin

The solution is not as trivial as I thought it would be. When there is an interface file it will affect what is inside the compiled interface file (.cmi) from which the .resi gets constructed. So an overwrite command would involve:

  1. Deleting the .resi file
  2. Starting a new build
  3. If the build is successful, there will be a new .cmi
  4. Now the updated .resi can be generated

Or is there a better way? @cristianoc

fhammerschmidt avatar Dec 09 '22 09:12 fhammerschmidt

I'd forgotten the command starts from the .cmi file. As all the other commands use .cmt.

cristianoc avatar Dec 10 '22 10:12 cristianoc

Since one can delete a file from within the editor, it's unlikely that a command will be created to do all theses operations at once when one can just use two commands within the editor, to delete the interface file, and create a new one.

cristianoc avatar Dec 13 '22 14:12 cristianoc

Another idea.

The server has a cache for the implementation file .res. We can add a command to analysis CLI to extract the signature of each structure_item. Similar to what is done for Code Lens.

In this case, we don't need to delete .resi

aspeddro avatar Mar 10 '23 22:03 aspeddro