-
Notifications
You must be signed in to change notification settings - Fork 563
initial support for F# #237
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
afe3b28
initial support for F#
brettfo 8fd37ae
plumb through language name
brettfo 958a109
allow code blocks of type `fsharp`
brettfo 65cce9f
consolidate region and buffer extraction
brettfo f1d41f9
add buffer/region extraction tests
brettfo e961f53
expand F# math demo
colombod 73d176a
format F# code with proper indentation levels
brettfo 5b4b8ea
use language switch
colombod 6754a0b
remove unnecessary interface property
brettfo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
|
|
||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <NoWarn>$(NoWarn);2003</NoWarn><!-- AssemblyInformationalVersionAttribute contains a non-standard value --> | ||
| </PropertyGroup> | ||
|
|
||
| <PropertyGroup Condition="$(TargetFramework.StartsWith('netstandard')) AND '$(OS)' == 'Windows_NT'"> | ||
| <!-- the 2.1.503 F# compiler can produce PDBs that can't properly be converted, see https://github.com/Microsoft/visualfsharp/issues/5976 --> | ||
| <PublishWindowsPdb>false</PublishWindowsPdb> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <Compile Include="Library.fs" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Update="FSharp.Core" Version="4.6.2" /> | ||
| <PackageReference Include="FSharp.Compiler.Service" Version="28.0.0" /> | ||
| <PackageReference Include="Microsoft.CodeAnalysis" Version="3.1.0-beta3-final" /> | ||
| </ItemGroup> | ||
|
|
||
| </Project> | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,130 @@ | ||
| namespace FSharpWorkspaceShim | ||
|
|
||
| open System | ||
| open System.IO | ||
| open FSharp.Compiler.SourceCodeServices | ||
| open Microsoft.CodeAnalysis | ||
| open Microsoft.CodeAnalysis.Text | ||
|
|
||
| module Shim = | ||
|
|
||
| let private checker = FSharpChecker.Create() | ||
|
|
||
| let private getIndex (text: string) (line: int) (column: int) = | ||
| let mutable index = -1 | ||
| let mutable currentLine = 0 | ||
| let mutable currentColumn = 0 | ||
| text.ToCharArray() | ||
| |> Array.iteri (fun i c -> | ||
| if line = currentLine && column = currentColumn then index <- i | ||
| match c with | ||
| | '\n' -> | ||
| currentLine <- currentLine + 1 | ||
| currentColumn <- 0 | ||
| | _ -> currentColumn <- currentColumn + 1) | ||
| index | ||
|
|
||
| let private newlineProxy = System.String [|char 29|] | ||
|
|
||
| // adapted from https://github.com/dotnet/fsharp/blob/master/src/fsharp/ErrorLogger.fs | ||
| let private normalizeErrorString (text : string) = | ||
| if isNull text then nullArg "text" | ||
| let text = text.Trim() | ||
|
|
||
| let buf = System.Text.StringBuilder() | ||
| let mutable i = 0 | ||
| while i < text.Length do | ||
| let delta = | ||
| match text.[i] with | ||
| | '\r' when i + 1 < text.Length && text.[i + 1] = '\n' -> | ||
| // handle \r\n sequence - replace it with one single space | ||
| buf.Append newlineProxy |> ignore | ||
| 2 | ||
| | '\n' | '\r' -> | ||
| buf.Append newlineProxy |> ignore | ||
| 1 | ||
| | c -> | ||
| // handle remaining chars: control - replace with space, others - keep unchanged | ||
| let c = if Char.IsControl c then ' ' else c | ||
| buf.Append c |> ignore | ||
| 1 | ||
| i <- i + delta | ||
| buf.ToString() | ||
|
|
||
| let private newlineifyErrorString (message:string) = message.Replace(newlineProxy, Environment.NewLine) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "newlineify" 😆
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Slightly shorter than |
||
|
|
||
| // adapted from https://github.com/dotnet/fsharp/blob/master/vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs | ||
| let private convertError (error: FSharpErrorInfo) (location: Location) = | ||
| // Normalize the error message into the same format that we will receive it from the compiler. | ||
| // This ensures that IntelliSense and Compiler errors in the 'Error List' are de-duplicated. | ||
| // (i.e the same error does not appear twice, where the only difference is the line endings.) | ||
| let normalizedMessage = error.Message |> normalizeErrorString |> newlineifyErrorString | ||
|
|
||
| let id = "FS" + error.ErrorNumber.ToString("0000") | ||
| let emptyString = LocalizableString.op_Implicit("") | ||
| let description = LocalizableString.op_Implicit(normalizedMessage) | ||
| let severity = if error.Severity = FSharpErrorSeverity.Error then DiagnosticSeverity.Error else DiagnosticSeverity.Warning | ||
| let customTags = | ||
| match error.ErrorNumber with | ||
| | 1182 -> WellKnownDiagnosticTags.Unnecessary | ||
| | _ -> null | ||
| let descriptor = new DiagnosticDescriptor(id, emptyString, description, error.Subcategory, severity, true, emptyString, String.Empty, customTags) | ||
| Diagnostic.Create(descriptor, location) | ||
|
|
||
| let GetDiagnostics (projectPath: string) (files: string[]) (pathMapSource: string) (pathMapDest: string) = | ||
| async { | ||
| let projectOptions = { | ||
| ProjectFileName = projectPath | ||
| ProjectId = None | ||
| SourceFiles = files | ||
| OtherOptions = [||] | ||
| ReferencedProjects = [||] | ||
| IsIncompleteTypeCheckEnvironment = false | ||
| UseScriptResolutionRules = false | ||
| LoadTime = DateTime.Now | ||
| UnresolvedReferences = None | ||
| OriginalLoadReferences = [] | ||
| ExtraProjectInfo = None | ||
| Stamp = None | ||
| } | ||
| let ensureDirectorySeparator (path: string) = | ||
| if path.EndsWith(Path.DirectorySeparatorChar |> string) |> not then path + (string Path.DirectorySeparatorChar) | ||
| else path | ||
| let pathMapSource = ensureDirectorySeparator pathMapSource | ||
| let pathMapDest = ensureDirectorySeparator pathMapDest | ||
| let! results = checker.ParseAndCheckProject projectOptions | ||
| // adapted from from https://github.com/dotnet/fsharp/blob/master/vsintegration/src/FSharp.Editor/Diagnostics/DocumentDiagnosticAnalyzer.fs | ||
| let diagnostics = | ||
| results.Errors | ||
| |> Seq.choose (fun error -> | ||
| if error.StartLineAlternate = 0 || error.EndLineAlternate = 0 then | ||
| // F# error line numbers are one-based. Compiler returns 0 for global errors (reported by ProjectDiagnosticAnalyzer) | ||
| None | ||
| else | ||
| // Roslyn line numbers are zero-based | ||
| let linePositionSpan = LinePositionSpan(LinePosition(error.StartLineAlternate - 1, error.StartColumn), LinePosition(error.EndLineAlternate - 1, error.EndColumn)) | ||
| let text = File.ReadAllText(error.FileName) | ||
| let textSpan = | ||
| TextSpan.FromBounds( | ||
| getIndex text (error.StartLineAlternate - 1) error.StartColumn, | ||
| getIndex text (error.EndLineAlternate - 1) error.EndColumn) | ||
|
|
||
| // F# compiler report errors at end of file if parsing fails. It should be corrected to match Roslyn boundaries | ||
| let correctedTextSpan = | ||
| if textSpan.End <= text.Length then | ||
| textSpan | ||
| else | ||
| let start = | ||
| min textSpan.Start (text.Length - 1) | ||
| |> max 0 | ||
|
|
||
| TextSpan.FromBounds(start, text.Length) | ||
|
|
||
| let filePath = | ||
| if error.FileName.StartsWith(pathMapSource) then String.Concat(pathMapDest, error.FileName.Substring(pathMapSource.Length)) | ||
| else error.FileName | ||
| let location = Location.Create(filePath, correctedTextSpan, linePositionSpan) | ||
| Some(convertError error location)) | ||
| |> Seq.toArray | ||
| return diagnostics | ||
| } |> Async.StartAsTask | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.