-
Notifications
You must be signed in to change notification settings - Fork 523
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial support for F# * plumb through language name * allow code blocks of type `fsharp` * consolidate region and buffer extraction * add buffer/region extraction tests * expand F# math demo * format F# code with proper indentation levels * use language switch * remove unnecessary interface property
- Loading branch information
Showing
49 changed files
with
862 additions
and
223 deletions.
There are no files selected for viewing
This file contains 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 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 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) | ||
|
||
// 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 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 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 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 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 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 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 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.