Skip to content

Commit

Permalink
Use var when type is apparent
Browse files Browse the repository at this point in the history
  • Loading branch information
DoctorKrolic committed Jan 2, 2024
1 parent 2f7b6e3 commit 9e12a6e
Show file tree
Hide file tree
Showing 49 changed files with 174 additions and 174 deletions.
8 changes: 4 additions & 4 deletions src/LanguageServer.Common/Utilities/DotNetRuntimeInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ static TextReader InvokeDotNetHost(string commandLineArguments, string baseDirec
if (logger == null)
throw new ArgumentNullException(nameof(logger));

Process dotnetHostProcess = new Process
var dotnetHostProcess = new Process
{
StartInfo = new ProcessStartInfo
{
Expand All @@ -285,15 +285,15 @@ static TextReader InvokeDotNetHost(string commandLineArguments, string baseDirec
string command = $"{dotnetHostProcess.StartInfo.FileName} {dotnetHostProcess.StartInfo.Arguments}";

// Buffer the output locally (otherwise, the process may hang if it fills up its STDOUT / STDERR buffer).
StringBuilder stdOutBuffer = new StringBuilder();
var stdOutBuffer = new StringBuilder();
dotnetHostProcess.OutputDataReceived += (sender, args) =>
{
lock (stdOutBuffer)
{
stdOutBuffer.AppendLine(args.Data);
}
};
StringBuilder stdErrBuffer = new StringBuilder();
var stdErrBuffer = new StringBuilder();
dotnetHostProcess.ErrorDataReceived += (sender, args) =>
{
lock (stdErrBuffer)
Expand Down Expand Up @@ -368,7 +368,7 @@ public static DotNetRuntimeInfo ParseDotNetInfoOutput(TextReader dotnetInfoOutpu
if (dotnetInfoOutput == null)
throw new ArgumentNullException(nameof(dotnetInfoOutput));

DotNetRuntimeInfo runtimeInfo = new DotNetRuntimeInfo();
var runtimeInfo = new DotNetRuntimeInfo();

DotnetInfoSection currentSection = DotnetInfoSection.Start;

Expand Down
10 changes: 5 additions & 5 deletions src/LanguageServer.Common/Utilities/MSBuildHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ public static void DiscoverMSBuildEngine(string baseDirectory = null, ILogger lo
// This will also ensure that the language server's model doesn't expose any MSBuild objects anywhere.
//
// For now, though, let's choose the dumb option.
DotNetRuntimeInfo runtimeInfo = DotNetRuntimeInfo.GetCurrent(baseDirectory, logger);
var runtimeInfo = DotNetRuntimeInfo.GetCurrent(baseDirectory, logger);

// SDK versions are in SemVer format...
if (!SemanticVersion.TryParse(runtimeInfo.SdkVersion, out SemanticVersion targetSdkSemanticVersion))
throw new Exception($"Cannot determine SDK version information for current .NET SDK (located at '{runtimeInfo.BaseDirectory}').");

// ...which MSBuildLocator does not understand.
Version targetSdkVersion = new Version(
var targetSdkVersion = new Version(
major: targetSdkSemanticVersion.Major,
minor: targetSdkSemanticVersion.Minor,
build: targetSdkSemanticVersion.Patch
Expand Down Expand Up @@ -175,7 +175,7 @@ public static ProjectCollection CreateProjectCollection(string solutionDirectory
Dictionary<string, string> globalProperties = CreateGlobalMSBuildProperties(runtimeInfo, solutionDirectory, globalPropertyOverrides);
EnsureMSBuildEnvironment(globalProperties);

ProjectCollection projectCollection = new ProjectCollection(globalProperties) { IsBuildEnabled = false };
var projectCollection = new ProjectCollection(globalProperties) { IsBuildEnabled = false };

if (!SemanticVersion.TryParse(runtimeInfo.SdkVersion, out SemanticVersion netcoreVersion))
throw new FormatException($"Cannot parse .NET SDK version '{runtimeInfo.SdkVersion}' (does not appear to be a valid semantic version).");
Expand All @@ -184,7 +184,7 @@ public static ProjectCollection CreateProjectCollection(string solutionDirectory
string toolsVersion = netcoreVersion <= NetCoreLastSdkVersionFor150Folder ? "15.0" : "Current";

// Override toolset paths (for some reason these point to the main directory where the dotnet executable lives).
Toolset toolset = new Toolset(toolsVersion,
var toolset = new Toolset(toolsVersion,
toolsPath: runtimeInfo.BaseDirectory,
projectCollection: projectCollection,
msbuildOverrideTasksPath: ""
Expand Down Expand Up @@ -336,7 +336,7 @@ public static Project CloneAsCachedProject(this Project project)
throw new ArgumentNullException(nameof(project));

ProjectRootElement clonedXml = project.Xml.DeepClone();
Project clonedProject = new Project(clonedXml, project.GlobalProperties, project.ToolsVersion, project.ProjectCollection)
var clonedProject = new Project(clonedXml, project.GlobalProperties, project.ToolsVersion, project.ProjectCollection)
{
FullPath = Path.ChangeExtension(project.FullPath,
".cached" + Path.GetExtension(project.FullPath)
Expand Down
10 changes: 5 additions & 5 deletions src/LanguageServer.Common/Utilities/NuGetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public static List<SourceRepository> CreateResourceRepositories(this IEnumerable
if (packageSources == null)
throw new ArgumentNullException(nameof(packageSources));

List<SourceRepository> sourceRepositories = new List<SourceRepository>();
var sourceRepositories = new List<SourceRepository>();

List<Lazy<INuGetResourceProvider>> providers = CreateResourceProviders(providerVersions);

foreach (PackageSource packageSource in packageSources)
{
SourceRepository sourceRepository = new SourceRepository(packageSource, providers);
var sourceRepository = new SourceRepository(packageSource, providers);

sourceRepositories.Add(sourceRepository);
}
Expand Down Expand Up @@ -110,7 +110,7 @@ public static SourceRepository CreateResourceRepository(this PackageSource packa
if (providers == null)
throw new ArgumentNullException(nameof(providers));

SourceRepository sourceRepository = new SourceRepository(packageSource, providers);
var sourceRepository = new SourceRepository(packageSource, providers);

return sourceRepository;
}
Expand Down Expand Up @@ -161,7 +161,7 @@ public static async Task<List<AutoCompleteResource>> GetAutoCompleteResources(IE
if (packageSources == null)
throw new ArgumentNullException(nameof(packageSources));

List<AutoCompleteResource> autoCompleteResources = new List<AutoCompleteResource>();
var autoCompleteResources = new List<AutoCompleteResource>();

List<SourceRepository> sourceRepositories = packageSources.CreateResourceRepositories();
foreach (SourceRepository sourceRepository in sourceRepositories)
Expand Down Expand Up @@ -249,7 +249,7 @@ public static async Task<SortedSet<NuGetVersion>> SuggestPackageVersions(this IE
IEnumerable<NuGetVersion>[] results = await Task.WhenAll(
autoCompleteResources.Select(async autoCompleteResource =>
{
using (SourceCacheContext cacheContext = new SourceCacheContext())
using (var cacheContext = new SourceCacheContext())
{
return await autoCompleteResource.VersionStartsWith(packageId, versionPrefix, includePrerelease, cacheContext, logger ?? NullLogger.Instance, cancellationToken);
}
Expand Down
2 changes: 1 addition & 1 deletion src/LanguageServer.Common/Utilities/TextPositions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ static int[] CalculateLineStartPositions(string text)
if (text == null)
throw new ArgumentNullException(nameof(text));

List<int> lineStarts = new List<int>();
var lineStarts = new List<int>();

int currentPosition = 0;
int currentLineStart = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
if (projectDocument == null)
throw new ArgumentNullException(nameof(projectDocument));

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
if (projectDocument == null)
throw new ArgumentNullException(nameof(projectDocument));

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

using (await projectDocument.Lock.ReaderLockAsync(cancellationToken))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
if (projectDocument == null)
throw new ArgumentNullException(nameof(projectDocument));

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l} (trigger characters = {TriggerCharacters})", location, triggerCharacters);

Expand Down Expand Up @@ -129,7 +129,7 @@ public IEnumerable<CompletionItem> GetCompletionItems(ProjectDocument projectDoc
{
LspModels.Range replaceRangeLsp = replaceRange.ToLsp();

HashSet<string> offeredItemNames = new HashSet<string>
var offeredItemNames = new HashSet<string>
{
"PackageReference",
"DotNetCliToolReference"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
if (projectDocument == null)
throw new ArgumentNullException(nameof(projectDocument));

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

Expand Down Expand Up @@ -116,7 +116,7 @@ public IEnumerable<CompletionItem> GetCompletionItems(ProjectDocument projectDoc
{
LspModels.Range replaceRangeLsp = replaceRange.ToLsp();

HashSet<string> offeredItemGroupNames = new HashSet<string>
var offeredItemGroupNames = new HashSet<string>
{
"*" // Skip virtual item type representing well-known metadata.
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

using (await projectDocument.Lock.ReaderLockAsync(cancellationToken))
{
Expand All @@ -67,7 +67,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
return null;
}

HashSet<string> existingMetadata = new HashSet<string>();
var existingMetadata = new HashSet<string>();

completions.AddRange(
GetAttributeCompletions(location, existingMetadata)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
if (projectDocument == null)
throw new ArgumentNullException(nameof(projectDocument));

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

Expand Down Expand Up @@ -193,7 +193,7 @@ public IEnumerable<CompletionItem> GetCompletionItems(ProjectDocument projectDoc
{
priority += 100;

SortedSet<string> metadataNames = new SortedSet<string>(
var metadataNames = new SortedSet<string>(
projectDocument.MSBuildProject.GetItems(targetItemType)
.SelectMany(
item => item.Metadata.Select(metadata => metadata.Name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
throw new ArgumentNullException(nameof(projectDocument));

bool isIncomplete = false;
List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
if (projectDocument == null)
throw new ArgumentNullException(nameof(projectDocument));

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

using (await projectDocument.Lock.ReaderLockAsync(cancellationToken))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
if (projectDocument == null)
throw new ArgumentNullException(nameof(projectDocument));

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

Expand Down Expand Up @@ -125,7 +125,7 @@ public IEnumerable<CompletionItem> GetCompletionItems(ProjectDocument projectDoc
{
LspModels.Range replaceRangeLsp = replaceRange.ToLsp();

HashSet<string> offeredPropertyNames = new HashSet<string>();
var offeredPropertyNames = new HashSet<string>();

// Well-known (but standard-format) properties.

Expand Down Expand Up @@ -223,7 +223,7 @@ CompletionItem PropertyCompletionItem(string propertyName, LspModels.Range repla
/// </returns>
static string GetCompletionText(string propertyName, IReadOnlyList<string> defaultValues)
{
StringBuilder completionText = new StringBuilder();
var completionText = new StringBuilder();
completionText.AppendFormat("<{0}>", propertyName);

bool haveValue = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
if (projectDocument == null)
throw new ArgumentNullException(nameof(projectDocument));

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

Expand Down Expand Up @@ -116,7 +116,7 @@ public IEnumerable<CompletionItem> GetCompletionItems(ProjectDocument projectDoc
{
LspModels.Range replaceRangeLsp = replaceRange.ToLsp();

HashSet<string> offeredPropertyNames = new HashSet<string>();
var offeredPropertyNames = new HashSet<string>();

// Well-known properties.
foreach (string wellKnownPropertyName in MSBuildSchemaHelp.WellKnownPropertyNames)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

using (await projectDocument.Lock.ReaderLockAsync(cancellationToken))
{
Expand All @@ -74,7 +74,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
}

Range targetRange = attribute.ValueRange;
HashSet<string> excludeTargetNames = new HashSet<string>();
var excludeTargetNames = new HashSet<string>();

// Handle potentially composite (i.e. "Value1;Value2;Value3") values, where it's legal to have them.
if (attribute.Name != "Name" && attribute.Value.IndexOf(';') != -1)
Expand Down Expand Up @@ -132,7 +132,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
/// </returns>
public IEnumerable<CompletionItem> GetCompletionItems(ProjectDocument projectDocument, Range replaceRange, HashSet<string> excludeTargetNames)
{
HashSet<string> offeredTargetNames = new HashSet<string>(excludeTargetNames);
var offeredTargetNames = new HashSet<string>(excludeTargetNames);
LspModels.Range replaceRangeLsp = replaceRange.ToLsp();

// Well-known targets.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected static Dictionary<string, MSBuildTaskMetadata> GetProjectTasks(Project

// We trust that all tasks discovered via GetMSBuildProjectTaskAssemblies are accessible in the current project.

Dictionary<string, MSBuildTaskMetadata> tasks = new Dictionary<string, MSBuildTaskMetadata>();
var tasks = new Dictionary<string, MSBuildTaskMetadata>();
foreach (MSBuildTaskAssemblyMetadata assemblyMetadata in projectDocument.GetMSBuildProjectTaskAssemblies())
{
foreach (MSBuildTaskMetadata task in assemblyMetadata.Tasks)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
return null;
}

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
return null;
}

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l}", location);

Expand Down Expand Up @@ -114,7 +114,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
);
}

HashSet<string> existingAttributeNames = new HashSet<string>(
var existingAttributeNames = new HashSet<string>(
taskElement.AttributeNames
);
if (replaceAttribute != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public override async Task<CompletionList> ProvideCompletionsAsync(XmlLocation l
if (projectDocument == null)
throw new ArgumentNullException(nameof(projectDocument));

List<CompletionItem> completions = new List<CompletionItem>();
var completions = new List<CompletionItem>();

Log.Verbose("Evaluate completions for {XmlLocation:l} (trigger characters = {TriggerCharacters})", location, triggerCharacters);

Expand Down
Loading

0 comments on commit 9e12a6e

Please sign in to comment.