I suggest we ...

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.

Before:

_program.fs_
let myQuery = "select a, b, c from mytable"

After:
_program.fs_
let myQuery = @mytable_query.sql

_mytable_query.sql_
select a, b, c
from mytable

8 votes
Vote
Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
You have left! (?) (thinking…)
Jeffrey Pierson shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

5 comments

Sign in
(thinking…)
Sign in with: facebook google
Signed in as (Sign out)
Submitting...
  • Jeffrey Pierson commented  ·   ·  Flag as inappropriate

    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.

  • Jeffrey Pierson commented  ·   ·  Flag as inappropriate

    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.

F# Language

Feedback and Knowledge Base