fsharp / fsharp/fslang-suggestions

Syntax highlighting for multi-line triple-quoted string content

Open
#1,300 7 comments 1 reaction 0 assignees View on GitHub
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

I propose we should have a way to do syntax highlighting (colour coding) of different content inside multi-line triple-quoted string.

Like markdown has: ```json or html and so on:

It might not be optimal to have other content in F# files, typically many times it's better to read separate external file. But also it's a bit over-kill to do file-operations every time. So you might see things like:

```fsharp
let emailContent = """...
```
or
```fsharp
type myRequest= FSharp.Data.JsonProvider< """[{ ...
```

...and then some 10-50 lines of single colour text without any intellisense or text correction. Hard to find any typos there.

Now, I don't know if this is purely editor thing or language feature: I suspect editors cannot infer content types without the core language change first. A lot of editors use things like compiler service to do things.

## Pros and Cons

The advantages of making this adjustment to F# are:
- Less typos in sometimes strictly formatted content, reduce issues bugs and debug time.

The disadvantages of making this adjustment to F# are:
- Possibly making already slow intellisense loading even slower in Visual Studio. So this should be the lowest priority background task.
- May lead more string-parsing code
- If there would be also fsharp option support within content, this could lead to yet another way to do easier unwanted metaprogramming, macros, recursion, etc.

## Extra information

I don't know the implementation details, what would be the best way to hint the file content type. Most editors already can do intellisense for basic types like html and json. So maybe something like this:

```fsharp
//markdown style
let mystr = """html
..."""

// or maybe parsing a comment or directive:
//#html
let mystr = """

// or maybe like attribute?
[]
let mystr = """...
```

## Affidavit

Please tick these items by placing a cross in the box:
* [x] This is not a question (e.g. like one you might ask on [StackOverflow](http://stackoverflow.com)) and I have searched StackOverflow for discussions of this issue
* [ ] This is a language change and not purely a tooling change (e.g. compiler bug, editor support, warning/error messages, new warning, non-breaking optimisation) belonging to [the compiler and tooling repository](https://github.com/dotnet/fsharp) (?)
* [x] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it
* [x] I have [searched both open and closed suggestions on this site](http://github.com/fsharp/fslang-suggestions/issues) and believe this is not a duplicate

Please tick all that apply:
* [x] This is not a breaking change to the F# language design
* [x] I or my company would be willing to help implement and/or test this

## For Readers

If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by determining whether the proposal belongs in the F# language, compiler service, or editor tooling, as the issue leaves that scope open. Review the examples of HTML, JSON, and Markdown content inside triple-quoted strings and the suggested comment, directive, and attribute forms. Done would require an agreed design and an implementation path for embedded-content syntax highlighting and related editor support.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.