Skip to content

Commit

Permalink
WarOn 1182 and 3390.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Nov 16, 2023
1 parent 2a26448 commit 8744661
Show file tree
Hide file tree
Showing 76 changed files with 2,362 additions and 2,204 deletions.
1 change: 1 addition & 0 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<PackageLicenseExpression Condition=" '$(PackAsTool)' != 'true' ">Apache-2.0</PackageLicenseExpression>
<NoWarn>$(NoWarn);3186,0042</NoWarn><!-- circumvent an error with the fake dependencymanager for paket: https://github.com/dotnet/fsharp/issues/8678 -->
<NoWarn>$(NoWarn);NU1902</NoWarn><!-- NU1902 - package vulnerability detected -->
<WarnOn>1182;3390;$(WarnOn)</WarnOn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<ChangelogFile>$(MSBuildThisFileDirectory)CHANGELOG.md</ChangelogFile>
</PropertyGroup>
Expand Down
5 changes: 3 additions & 2 deletions benchmarks/Program.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Benchmarks

open System
open BenchmarkDotNet
open BenchmarkDotNet.Attributes
Expand All @@ -11,6 +12,6 @@ open System.Security.Cryptography
module EntryPoint =

[<EntryPoint>]
let main argv =
let summary = BenchmarkRunner.Run<SourceText_LineChanges_Benchmarks>();
let main _argv =
let _summary = BenchmarkRunner.Run<SourceText_LineChanges_Benchmarks>()
0
2 changes: 0 additions & 2 deletions build/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ let init args =
Context.setExecutionContext (Context.RuntimeContext.Fake execContext)
Target.initEnvironment ()

let fsacAssemblies = "FsAutoComplete|FsAutoComplete.Core|LanguageServerProtocol"

let packAsToolProp = "PackAsTool", "true"

Target.create "LspTest" (fun _ ->
Expand Down
25 changes: 13 additions & 12 deletions src/FsAutoComplete.Core/AbstractClassStubGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let private (|ExplicitCtor|_|) =
| _ -> None

/// checks to see if a type definition inherits an abstract class, and if so collects the members defined at that
let private walkTypeDefn (SynTypeDefn(info, repr, members, implicitCtor, range, trivia)) =
let private walkTypeDefn (SynTypeDefn(_, repr, members, implicitCtor, _, _)) =
option {
let reprMembers =
match repr with
Expand All @@ -46,7 +46,7 @@ let private walkTypeDefn (SynTypeDefn(info, repr, members, implicitCtor, range,
let! inheritType, inheritMemberRange = // this must exist for abstract types
allMembers
|> List.tryPick (function
| SynMemberDefn.ImplicitInherit(inheritType, inheritArgs, alias, range) -> Some(inheritType, range)
| SynMemberDefn.ImplicitInherit(inheritType, _, _, range) -> Some(inheritType, range)
| _ -> None)

let furthestMemberToSkip, otherMembers =
Expand Down Expand Up @@ -81,13 +81,14 @@ let private tryFindAbstractClassExprInParsedInput
{ new SyntaxVisitorBase<_>() with
member _.VisitExpr(path, traverseExpr, defaultTraverse, expr) =
match expr with
| SynExpr.ObjExpr(baseTy, constructorArgs, withKeyword, bindings, members, extraImpls, newExprRange, range) ->
| SynExpr.ObjExpr(
objType = baseTy; withKeyword = withKeyword; bindings = bindings; newExprRange = newExprRange) ->
Some(AbstractClassData.ObjExpr(baseTy, bindings, newExprRange, withKeyword))
| _ -> defaultTraverse expr

override _.VisitModuleDecl(_, defaultTraverse, decl) =
match decl with
| SynModuleDecl.Types(types, m) -> List.tryPick walkTypeDefn types
| SynModuleDecl.Types(types, _) -> List.tryPick walkTypeDefn types
| _ -> defaultTraverse decl }
)

Expand All @@ -103,12 +104,12 @@ let tryFindAbstractClassExprInBufferAtPos
return! tryFindAbstractClassExprInParsedInput pos parseResults.ParseTree
}

let getMemberNameAndRanges (abstractClassData) =
let getMemberNameAndRanges abstractClassData =
match abstractClassData with
| AbstractClassData.ExplicitImpl(members = members) ->
members
|> Seq.choose (function
| (SynMemberDefn.Member(binding, _)) -> Some binding
| SynMemberDefn.Member(binding, _) -> Some binding
| _ -> None)
|> Seq.choose (|MemberNamePlusRangeAndKeywordRange|_|)
|> Seq.toList
Expand All @@ -129,7 +130,7 @@ let inferStartColumn
| AbstractClassData.ExplicitImpl(inheritExpressionRange = inheritRange) ->
// 'interface ISomething with' is often in a new line, we use the indentation of that line
inheritRange.StartColumn
| AbstractClassData.ObjExpr(newExpression = newExpr; withKeyword = withKeyword; bindings = bindings) ->
| AbstractClassData.ObjExpr(newExpression = newExpr; withKeyword = withKeyword; bindings = _) ->
// two cases here to consider:
// * has a with keyword on same line as newExpr
match withKeyword with
Expand All @@ -152,19 +153,19 @@ let writeAbstractClassStub
(codeGenServer: ICodeGenerationService)
(checkResultForFile: ParseAndCheckResults)
(doc: IFSACSourceText)
(lineStr: string)
(_: string)
(abstractClassData: AbstractClassData)
=
asyncOption {
let pos =
Position.mkPos
abstractClassData.AbstractTypeIdentRange.Start.Line
(abstractClassData.AbstractTypeIdentRange.End.Column)
abstractClassData.AbstractTypeIdentRange.End.Column

let! (_lexerSym, usages) = codeGenServer.GetSymbolAndUseAtPositionOfKind(doc.FileName, pos, SymbolKind.Ident)
let! _lexerSym, usages = codeGenServer.GetSymbolAndUseAtPositionOfKind(doc.FileName, pos, SymbolKind.Ident)
let! usage = usages

let! (displayContext, entity) =
let! displayContext, entity =
asyncOption {
// need the enclosing entity because we're always looking at a ctor, which isn't an Entity, but a MemberOrFunctionOrValue
match usage.Symbol with
Expand All @@ -177,7 +178,7 @@ let writeAbstractClassStub
| _ -> return! None
}

let getMemberByLocation (name: string, range: Range, keywordRange: Range) =
let getMemberByLocation (_: string, range: Range, _: Range) =
match doc.GetLine range.Start with
| Some lineText ->
match Lexer.getSymbol range.Start.Line range.Start.Column lineText SymbolLookupKind.ByLongIdent [||] with
Expand Down
8 changes: 4 additions & 4 deletions src/FsAutoComplete.Core/AdaptiveExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ type MapDisposableTupleVal<'T1, 'T2, 'Disposable when 'Disposable :> IDisposable

match cache with
| ValueSome(struct (a, b, _)) when Utils.cheapEqual a i -> b
| ValueSome(struct (a, b, c)) ->
| ValueSome(struct (_, _, c)) ->
(c :> IDisposable).Dispose()
let (b, c) = mapping i
cache <- ValueSome(struct (i, b, c))
Expand Down Expand Up @@ -209,7 +209,7 @@ module AMap =
dirty <- HashMap.empty
d)

override x.InputChangedObject(t, o) =
override x.InputChangedObject(_, o) =
#if FABLE_COMPILER
if isNull o.Tag then
let o = unbox<aval<'b>> o
Expand Down Expand Up @@ -316,7 +316,7 @@ module AMap =
=
let mapping =
mapping
>> HashMap.map (fun _ v -> AVal.constant v |> AVal.mapWithAdditionalDependencies (id))
>> HashMap.map (fun _ v -> AVal.constant v |> AVal.mapWithAdditionalDependencies id)

batchRecalcDirty mapping map

Expand Down Expand Up @@ -416,7 +416,7 @@ module Async =
return! ct.Task |> Async.AwaitTask
}

[<AutoOpenAttribute>]
[<AutoOpen>]
module Extensions =

type IcedTasks.CancellableTaskBase.CancellableTaskBuilderBase with
Expand Down
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/CodeGeneration.fs
Original file line number Diff line number Diff line change
Expand Up @@ -554,7 +554,7 @@ module CodeGenerationUtils =

let getAbstractNonVirtualMembers (e: FSharpEntity) =
seq {
let genericParams = e.GenericParameters :> seq<_>
let _genericParams = e.GenericParameters :> seq<_>
// todo: generic param instantiations?
yield!
e.MembersFunctionsAndValues
Expand Down
17 changes: 7 additions & 10 deletions src/FsAutoComplete.Core/Commands.fs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ module Commands =
(tyRes: ParseAndCheckResults)
(pos: Position)
(lines: IFSACSourceText)
(line: LineStr)
=
async {
let doc = docForText lines tyRes
Expand Down Expand Up @@ -363,7 +362,6 @@ module Commands =
(tyRes: ParseAndCheckResults)
(pos: Position)
(lines: ISourceText)
(line: LineStr)
=
async {

Expand Down Expand Up @@ -562,8 +560,8 @@ module Commands =

let getStartingPipe =
function
| y :: xs when y.TokenName.ToUpper() = "INFIX_BAR_OP" -> Some y
| x :: y :: xs when x.TokenName.ToUpper() = "WHITESPACE" && y.TokenName.ToUpper() = "INFIX_BAR_OP" -> Some y
| y :: _ when y.TokenName.ToUpper() = "INFIX_BAR_OP" -> Some y
| x :: y :: _ when x.TokenName.ToUpper() = "WHITESPACE" && y.TokenName.ToUpper() = "INFIX_BAR_OP" -> Some y
| _ -> None

let folder (lastExpressionLine, lastExpressionLineWasPipe, acc) (currentIndex, currentTokens) =
Expand Down Expand Up @@ -634,8 +632,8 @@ module Commands =

let getStartingPipe =
function
| y :: xs when y.TokenName.ToUpper() = "INFIX_BAR_OP" -> Some y
| x :: y :: xs when x.TokenName.ToUpper() = "WHITESPACE" && y.TokenName.ToUpper() = "INFIX_BAR_OP" -> Some y
| y :: _ when y.TokenName.ToUpper() = "INFIX_BAR_OP" -> Some y
| x :: y :: _ when x.TokenName.ToUpper() = "WHITESPACE" && y.TokenName.ToUpper() = "INFIX_BAR_OP" -> Some y
| _ -> None

let folder (lastExpressionLine, lastExpressionLineWasPipe, acc) (currentIndex, currentTokens) =
Expand Down Expand Up @@ -716,7 +714,7 @@ module Commands =
// adjust column
let pos =
match pos with
| Pos(1, c) -> pos
| Pos(1, _) -> pos
| Pos(l, 0) ->
let prev = getLine (pos.DecLine())
let indentation = detectIndentation prev
Expand All @@ -726,7 +724,7 @@ module Commands =
Position.mkPos l indentation
else
pos
| Pos(_, c) -> pos
| Pos(_, _) -> pos

{ Namespace = n
Position = pos
Expand Down Expand Up @@ -795,7 +793,6 @@ module Commands =
match scope with
| Some(SymbolDeclarationLocation.Projects(projects (*isLocalForProject=*) , true)) -> return projects
| Some(SymbolDeclarationLocation.Projects(projects (*isLocalForProject=*) , false)) ->
let output = ResizeArray<_>()

let! resolvedProjects =
[ for project in projects do
Expand Down Expand Up @@ -979,7 +976,7 @@ module Commands =
///
/// Also does very basic validation of `newName`:
/// * Must be valid operator name when operator
let adjustRenameSymbolNewName pos lineStr (text: IFSACSourceText) (tyRes: ParseAndCheckResults) (newName: string) =
let adjustRenameSymbolNewName pos lineStr (tyRes: ParseAndCheckResults) (newName: string) =
asyncResult {
let! symbolUse =
tyRes.TryGetSymbolUse pos lineStr
Expand Down
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/Debug.fs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ module Debug =
return r
}

let toggleVerboseLogging (verbose: bool) = () // todo: set logging latch
let toggleVerboseLogging (_verbose: bool) = () // todo: set logging latch

let waitForDebugger () =
while not (Diagnostics.Debugger.IsAttached) do
Expand Down
5 changes: 2 additions & 3 deletions src/FsAutoComplete.Core/DocumentationFormatter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ module DocumentationFormatter =

sprintf "active pattern %s: %s" apc.Name findVal

let getAttributeSignature displayContext (attr: FSharpAttribute) =
let getAttributeSignature (attr: FSharpAttribute) =
let name =
formatShowDocumentationLink
attr.AttributeType.DisplayName
Expand Down Expand Up @@ -717,8 +717,7 @@ module DocumentationFormatter =
|> Seq.map (fun inf -> fst (format displayContext inf))
|> Seq.toArray

let attrs =
fse.Attributes |> Seq.map (getAttributeSignature displayContext) |> Seq.toArray
let attrs = fse.Attributes |> Seq.map getAttributeSignature |> Seq.toArray

let types =
fse.NestedEntities
Expand Down
7 changes: 5 additions & 2 deletions src/FsAutoComplete.Core/DotnetNewTemplate.fs
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,11 @@ module DotnetNewTemplate =
let templates =
templateDetails ()
|> List.map (fun t -> t, extractDetailedString t)
|> List.filter (fun (t, strings) -> strings |> List.exists (nameMatch userInput))
|> List.map (fun (t, strings) -> t)
|> List.choose (fun (t, strings) ->
if strings |> List.exists (nameMatch userInput) then
Some t
else
None)

match templates with
| [] -> failwithf "No template exists with name : %s" userInput
Expand Down
6 changes: 3 additions & 3 deletions src/FsAutoComplete.Core/FCSPatches.fs
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ module SyntaxTreeOps =
(match copyInfo with
| Some(e, _) -> walkExpr e
| None -> false)
|| walkExprs (recordFields |> List.map (fun (ident, range, expr) -> expr))
|| walkExprs (recordFields |> List.map (fun (_ident, _range, expr) -> expr))

| SynExpr.Record(copyInfo = copyInfo; recordFields = recordFields) ->
(match copyInfo with
Expand Down Expand Up @@ -540,11 +540,11 @@ module SyntaxTreeOps =
| SynInterpolatedStringPart.String _ -> None
| SynInterpolatedStringPart.FillExpr(x, _) -> Some x)
)
| SynExpr.IndexRange(expr1, opm, expr2, range1, range2, range3) ->
| SynExpr.IndexRange(expr1 = expr1; expr2 = expr2) ->
Option.map walkExpr expr1
|> Option.orElseWith (fun _ -> Option.map walkExpr expr2)
|> Option.defaultValue false
| SynExpr.IndexFromEnd(expr, range) -> walkExpr expr
| SynExpr.IndexFromEnd(expr, _) -> walkExpr expr
| SynExpr.DebugPoint(innerExpr = expr) -> walkExpr expr
| SynExpr.Dynamic(funcExpr = funcExpr; argExpr = argExpr) -> walkExpr funcExpr || walkExpr argExpr

Expand Down
2 changes: 1 addition & 1 deletion src/FsAutoComplete.Core/Fsdn.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ let query (queryStr: string) =

let info2 = v.api.name
//return a list of strings
let infoNamespace = info2.``namespace``
let _infoNamespace = info2.``namespace``
let infoClass = info2.class_name
let infoMethod = info2.id

Expand Down
30 changes: 15 additions & 15 deletions src/FsAutoComplete.Core/InlayHints.fs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ type private FSharp.Compiler.CodeAnalysis.FSharpParseFileResults with
match binding with
| SynBinding(
headPat = SynPat.Named(range = patRange)
returnInfo = Some(SynBindingReturnInfo(typeName = SynType.LongIdent(idents)))) -> Some patRange
returnInfo = Some(SynBindingReturnInfo(typeName = SynType.LongIdent _))) -> Some patRange
| _ -> defaultTraverse binding }

let result = SyntaxTraversal.Traverse(pos, x.ParseTree, visitor)
Expand Down Expand Up @@ -316,16 +316,16 @@ module private ShouldCreate =

isPostfixOf funcName paramName

/// </summary>
/// We filter out parameters that generate lots of noise in hints.
/// * parameter has no name
/// * parameter has length > 2
/// * parameter is one of a set of 'known' names that clutter (like printfn formats)
/// * param & function is "well known"/commonly used
/// * parameter does match or is a pre/postfix of user-entered text
/// * user-entered text does match or is a pre/postfix of parameter
/// * parameter is postfix of function name
/// </summary>
// /// <summary>
// /// We filter out parameters that generate lots of noise in hints.
// /// * parameter has no name
// /// * parameter has length > 2
// /// * parameter is one of a set of 'known' names that clutter (like printfn formats)
// /// * param & function is "well known"/commonly used
// /// * parameter does match or is a pre/postfix of user-entered text
// /// * user-entered text does match or is a pre/postfix of parameter
// /// * parameter is postfix of function name
// /// </summary>
let paramHint (func: FSharpMemberOrFunctionOrValue) (p: FSharpParameter) (argumentText: string) =
hasName p
&& isMeaningfulName p
Expand Down Expand Up @@ -620,7 +620,7 @@ let tryGetExplicitTypeInfo (text: IFSACSourceText, ast: ParsedInput) (pos: Posit
| _ -> defaultTraverse expr

member visitor.VisitPat(path, defaultTraverse, pat) =
let invalidPositionForTypeAnnotation (pos: Position) (path: SyntaxNode list) =
let invalidPositionForTypeAnnotation (path: SyntaxNode list) =
match path with
| SyntaxNode.SynExpr(SynExpr.LetOrUseBang(isUse = true)) :: _ ->
// use! value =
Expand All @@ -641,7 +641,7 @@ let tryGetExplicitTypeInfo (text: IFSACSourceText, ast: ParsedInput) (pos: Posit
// see dotnet/fsharp#13115
// | _ when not (rangeContainsPos pat.Range pos) -> None
| SynPat.Named(ident = SynIdent(ident = ident)) when
rangeContainsPos ident.idRange pos && invalidPositionForTypeAnnotation pos path
rangeContainsPos ident.idRange pos && invalidPositionForTypeAnnotation path
->
ExplicitType.Invalid |> Some
| SynPat.Named(ident = SynIdent(ident = ident); isThisVal = false) when rangeContainsPos ident.idRange pos ->
Expand Down Expand Up @@ -770,7 +770,7 @@ let private getArgRangesOfFunctionApplication (ast: ParsedInput) pos =
{ new SyntaxVisitorBase<_>() with
member _.VisitExpr(_, traverseSynExpr, defaultTraverse, expr) =
match expr with
| SynExpr.App(isInfix = false; funcExpr = funcExpr; argExpr = argExpr; range = range) when pos = range.Start ->
| SynExpr.App(isInfix = false; funcExpr = funcExpr; range = range) when pos = range.Start ->
let isInfixFuncExpr =
match funcExpr with
| SynExpr.App(_, isInfix, _, _, _) -> isInfix
Expand Down Expand Up @@ -828,7 +828,7 @@ let private getArgRangesOfFunctionApplication (ast: ParsedInput) pos =
/// `let map f v = f v` -> `f` is target
let isPotentialTargetForTypeAnnotation
(allowFunctionValues: bool)
(symbolUse: FSharpSymbolUse, mfv: FSharpMemberOrFunctionOrValue)
(_symbolUse: FSharpSymbolUse, mfv: FSharpMemberOrFunctionOrValue)
=
//ENHANCEMENT: extract settings
(mfv.IsValue || (allowFunctionValues && mfv.IsFunction))
Expand Down
Loading

0 comments on commit 8744661

Please sign in to comment.