mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-01-20 01:25:41 -05:00
- Additional handling of document events with "perforce:" or other SCM strings - Much of the handling had been added already, but adding in additional validation and ensuring that everywhere `Workspace.GetFile` is called we add a not-null check to avoid null reference errors
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
//
|
||||
using System;
|
||||
using System.IO;
|
||||
namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
{
|
||||
internal static class FileUtilities
|
||||
{
|
||||
@@ -136,8 +136,18 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
|
||||
File.SetAttributes(fullFilePath, FileAttributes.Normal);
|
||||
}
|
||||
}
|
||||
|
||||
internal static ResolvedFile TryGetFullPath(string filePath)
|
||||
{
|
||||
try
|
||||
{
|
||||
return new ResolvedFile(Path.GetFullPath(filePath), true);
|
||||
}
|
||||
catch(NotSupportedException)
|
||||
{
|
||||
// This is not a standard path.
|
||||
return new ResolvedFile(filePath, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
39
src/Microsoft.SqlTools.ServiceLayer/Utility/ResolvedFile.cs
Normal file
39
src/Microsoft.SqlTools.ServiceLayer/Utility/ResolvedFile.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
//
|
||||
// Copyright (c) Microsoft. All rights reserved.
|
||||
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
|
||||
//
|
||||
|
||||
|
||||
namespace Microsoft.SqlTools.ServiceLayer.Utility
|
||||
{
|
||||
/// <summary>
|
||||
/// Utility object holding a result of a file resolve action.
|
||||
///
|
||||
/// Workspace APIs support reading from disk if a file hasn't been
|
||||
/// officially opened via VSCode APIs with a buffer. This is problematic
|
||||
/// in the case where it's not a file on disk as any attempt will cause
|
||||
/// an exception to be thrown.
|
||||
///
|
||||
/// To mitigate this a ResolvedFile object has an additional flag indicating
|
||||
/// if the file can be read from disk.
|
||||
/// </summary>
|
||||
internal class ResolvedFile
|
||||
{
|
||||
public ResolvedFile(string filePath, bool canReadFromDisk)
|
||||
{
|
||||
FilePath = filePath;
|
||||
CanReadFromDisk = canReadFromDisk;
|
||||
}
|
||||
|
||||
public string FilePath { get; private set; }
|
||||
public bool CanReadFromDisk { get; private set; }
|
||||
|
||||
public string LowercaseFilePath
|
||||
{
|
||||
get
|
||||
{
|
||||
return FilePath?.ToLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user