Add feature to allow string literals to be separated into text files
Often in code there is a block of meta language in a string format. Typical examples could be SQL, XML, JSON, MD, or just plain text. The choices a developer normally has is either to embed the text as a string literal or to spearate into a file. Separating into a file normally has some advantages in that the format gets better editing support (ex. MyQuery.sql has a nice editing experience than an embedded string) and it cleans up the related code. The down side is traditionally that now the file is read in at runtime and the tooling support in the code to go to the text file for a given string definition becomes more of a manual process.
What I would like to propose is the idea of a string literal where the value can be specified in a referenced text file.
let myQuery = "select a, b, c from mytable"
let myQuery = @mytable_query.sql
select a, b, c
Having a type provider to read string literals from files is entirely reasonable.
I am marking this as declined for the F# language itself because the functionality can be implemented using F# type providers. My suggestion is to open an issue at https://github.com/fsprojects/FSharp.Management/issues
F# Language Evolution
Jeffrey Pierson commented
I'm going to try to implement a basic type provider to accomplish this but one use consideration is for tooling in order to allow things like go to definition to work in Visual Studio or Ionide using F12 and the like. The manual process of navigating to the file is essentially what I want to ignore. Seeing the literal value in the editor too in a mouse hover would be helpful as well. I'll see how far a type provider gets me with respect to both of these and perhaps push for better type provider tooling in these editors if it falls short as is.
Gauthier Segay commented
Jeffrey Pierson, please look at this type provider I created to read a .csv file, parse values from a single column, and generate distinct string literals from those:
I think your feature request is "as simple as you could get" exercise to write your first type provider :)
Don Syme commented
This is possible with F# type providers, but the functionality needs to be implemented. I tweeted a request for someone to help with this here: https://twitter.com/dsyme/status/742300239739166720
Jeffrey Pierson commented
Radek Micek - care to share how? I haven't found any available type provider for string literals and looking into how to create a custom type provider has led me into what seems to be a deep rabbit hole.
Radek Micek commented
You can do that with type providers.