-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for custom type declaration sources.
- Loading branch information
1 parent
9a443c6
commit 972658f
Showing
15 changed files
with
252 additions
and
133 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
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 was deleted.
Oops, something went wrong.
35 changes: 35 additions & 0 deletions
35
src/Blazor.SourceGenerators/Readers/TypeDeclarationReader.Factory.cs
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,35 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Blazor.SourceGenerators.Readers; | ||
|
||
internal sealed partial class TypeDeclarationReader | ||
{ | ||
static readonly ConcurrentDictionary<string, TypeDeclarationReader> s_readerCache = | ||
new(StringComparer.OrdinalIgnoreCase); | ||
|
||
internal static TypeDeclarationReader Factory(string source) | ||
{ | ||
var uri = new Uri(source); | ||
var sourceKey = uri.IsFile ? uri.LocalPath : uri.OriginalString; | ||
|
||
var reader = | ||
s_readerCache.GetOrAdd( | ||
sourceKey, _ => new TypeDeclarationReader(uri)); | ||
|
||
return reader; | ||
} | ||
|
||
internal static TypeDeclarationReader Default | ||
{ | ||
get | ||
{ | ||
var sourceKey = s_defaultTypeDeclarationSource.OriginalString; | ||
var reader = | ||
s_readerCache.GetOrAdd( | ||
sourceKey, _ => new TypeDeclarationReader(s_defaultTypeDeclarationSource)); | ||
|
||
return reader; | ||
} | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/Blazor.SourceGenerators/Readers/TypeDeclarationReader.LocalFiles.cs
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,9 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Blazor.SourceGenerators.Readers; | ||
|
||
internal sealed partial class TypeDeclarationReader | ||
{ | ||
string GetLocalFileText(string filePath) => File.ReadAllText(filePath); | ||
} |
22 changes: 22 additions & 0 deletions
22
src/Blazor.SourceGenerators/Readers/TypeDeclarationReader.RemoteFile.cs
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,22 @@ | ||
// Copyright (c) David Pine. All rights reserved. | ||
// Licensed under the MIT License. | ||
|
||
namespace Blazor.SourceGenerators.Readers; | ||
|
||
internal sealed partial class TypeDeclarationReader | ||
{ | ||
static readonly HttpClient s_httpClient = new(); | ||
static readonly Uri s_defaultTypeDeclarationSource = | ||
new("https://raw.githubusercontent.com/microsoft/TypeScript/main/lib/lib.dom.d.ts"); | ||
|
||
string GetRemoteFileText(string url) | ||
{ | ||
var typeDeclarationText = | ||
s_httpClient.GetStringAsync(url) | ||
.ConfigureAwait(false) | ||
.GetAwaiter() | ||
.GetResult(); | ||
|
||
return typeDeclarationText; | ||
} | ||
} |
Oops, something went wrong.