Browse Source

Handle C++ 2010 runtime not installed which is needed for TypeScript.

If the Microsoft Visual C++ 2010 Redistributable Package (x86) was not
installed then a file not found exception was thrown by the TypeScript
addin. This exception is now handled and the parser adds an error to
the Errors list indicating that the C++ runtime should be installed
from the following link:

https://www.microsoft.com/en-us/download/details.aspx?id=5555
pull/731/head
Matt Ward 10 years ago
parent
commit
70cf4bf45f
  1. 43
      src/AddIns/BackendBindings/TypeScript/Project/Src/Hosting/DefaultJavaScriptContext.cs
  2. 28
      src/AddIns/BackendBindings/TypeScript/Project/Src/Hosting/IJavaScriptContext.cs
  3. 52
      src/AddIns/BackendBindings/TypeScript/Project/Src/Hosting/TypeScriptContext.cs
  4. 14
      src/AddIns/BackendBindings/TypeScript/Project/Src/Hosting/TypeScriptContextFactory.cs
  5. 2
      src/AddIns/BackendBindings/TypeScript/Project/TypeScriptBinding.csproj
  6. 2
      src/AddIns/BackendBindings/TypeScript/Test/Parsing/ParseTests.cs

43
src/AddIns/BackendBindings/TypeScript/Project/Src/Hosting/DefaultJavaScriptContext.cs

@ -0,0 +1,43 @@ @@ -0,0 +1,43 @@
// Copyright (c) 2015 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
using Noesis.Javascript;
namespace ICSharpCode.TypeScriptBinding.Hosting
{
public class DefaultJavaScriptContext : IJavaScriptContext
{
readonly JavascriptContext context = new JavascriptContext();
public void SetParameter(string name, object value)
{
context.SetParameter(name, value);
}
public void Run(string script)
{
context.Run(script);
}
public void Dispose()
{
context.Dispose();
}
}
}

28
src/AddIns/BackendBindings/TypeScript/Project/Src/Hosting/IJavaScriptContext.cs

@ -0,0 +1,28 @@ @@ -0,0 +1,28 @@
// Copyright (c) 2015 AlphaSierraPapa for the SharpDevelop Team
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
// software and associated documentation files (the "Software"), to deal in the Software
// without restriction, including without limitation the rights to use, copy, modify, merge,
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
// to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
using System;
namespace ICSharpCode.TypeScriptBinding.Hosting
{
public interface IJavaScriptContext : IDisposable
{
void SetParameter(string name, object value);
void Run(string script);
}
}

52
src/AddIns/BackendBindings/TypeScript/Project/Src/Hosting/TypeScriptContext.cs

@ -39,24 +39,30 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -39,24 +39,30 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
{
public class TypeScriptContext : IDisposable
{
JavascriptContext context = new JavascriptContext();
IJavaScriptContext context;
LanguageServiceShimHost host;
TypeScriptProject project;
IScriptLoader scriptLoader;
bool runInitialization = true;
public TypeScriptContext(IScriptLoader scriptLoader, ILogger logger)
public TypeScriptContext(IJavaScriptContext context, IScriptLoader scriptLoader, ILogger logger)
{
this.context = context;
this.scriptLoader = scriptLoader;
host = new LanguageServiceShimHost(logger);
host.AddDefaultLibScript(new FileName(scriptLoader.LibScriptFileName), scriptLoader.GetLibScript());
context.SetParameter("host", host);
context.Run(scriptLoader.GetTypeScriptServicesScript());
if (context != null) {
context.SetParameter("host", host);
context.Run(scriptLoader.GetTypeScriptServicesScript());
}
}
public void Dispose()
{
context.Dispose();
if (context != null) {
context.Dispose();
}
}
public void AddFile(FileName fileName, string text)
@ -68,7 +74,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -68,7 +74,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
{
if (runInitialization) {
runInitialization = false;
context.Run(scriptLoader.GetMainScript());
if (context != null) {
context.Run(scriptLoader.GetMainScript());
}
}
}
@ -89,6 +97,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -89,6 +97,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
public CompletionInfo GetCompletionItems(FileName fileName, int offset, string text, bool memberCompletion)
{
if (context == null)
return new CompletionInfo();
UpdateCompilerSettings();
host.position = offset;
host.UpdateFileName(fileName);
@ -101,6 +112,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -101,6 +112,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
public CompletionEntryDetails GetCompletionEntryDetails(FileName fileName, int offset, string entryName)
{
if (context == null)
return new CompletionEntryDetails();
UpdateCompilerSettings();
host.position = offset;
host.UpdateFileName(fileName);
@ -113,6 +127,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -113,6 +127,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
public SignatureHelpItems GetSignature(FileName fileName, int offset)
{
if (context == null)
return new SignatureHelpItems();
UpdateCompilerSettings();
host.position = offset;
host.UpdateFileName(fileName);
@ -124,6 +141,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -124,6 +141,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
public ReferenceEntry[] FindReferences(FileName fileName, int offset)
{
if (context == null)
return new ReferenceEntry[0];
UpdateCompilerSettings();
host.position = offset;
host.UpdateFileName(fileName);
@ -135,6 +155,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -135,6 +155,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
public DefinitionInfo[] GetDefinition(FileName fileName, int offset)
{
if (context == null)
return new DefinitionInfo[0];
UpdateCompilerSettings();
host.position = offset;
host.UpdateFileName(fileName);
@ -146,6 +169,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -146,6 +169,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
public NavigationBarItem[] GetNavigationInfo(FileName fileName)
{
if (context == null)
return new NavigationBarItem[0];
UpdateCompilerSettings();
host.UpdateFileName(fileName);
context.Run(scriptLoader.GetNavigationScript());
@ -160,6 +186,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -160,6 +186,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
public EmitOutput Compile(FileName fileName, ITypeScriptOptions options)
{
if (context == null)
return new EmitOutput();
host.UpdateCompilerSettings(options);
host.UpdateFileName(fileName);
context.Run(scriptLoader.GetLanguageServicesCompileScript());
@ -169,6 +198,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -169,6 +198,9 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
public Diagnostic[] GetDiagnostics(FileName fileName, ITypeScriptOptions options)
{
if (context == null)
return new [] { GetMicrosoftRuntimeNotInstalledDiagnostic() };
host.UpdateCompilerSettings(options);
host.UpdateFileName(fileName);
context.Run(scriptLoader.GetDiagnosticsScript());
@ -196,5 +228,13 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -196,5 +228,13 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
host.UpdateCompilerSettings(project);
}
}
Diagnostic GetMicrosoftRuntimeNotInstalledDiagnostic()
{
return new Diagnostic {
category = DiagnosticCategory.Error,
message = "Microsoft Visual C++ 2010 Redistributable Package is not installed. https://www.microsoft.com/en-us/download/details.aspx?id=5555"
};
}
}
}

14
src/AddIns/BackendBindings/TypeScript/Project/Src/Hosting/TypeScriptContextFactory.cs

@ -27,6 +27,8 @@ @@ -27,6 +27,8 @@
//
using System;
using System.IO;
using ICSharpCode.Core;
namespace ICSharpCode.TypeScriptBinding.Hosting
{
@ -48,7 +50,17 @@ namespace ICSharpCode.TypeScriptBinding.Hosting @@ -48,7 +50,17 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
public TypeScriptContext CreateContext()
{
return new TypeScriptContext(scriptLoader, logger);
return new TypeScriptContext(CreateJavaScriptContext(), scriptLoader, logger);
}
IJavaScriptContext CreateJavaScriptContext()
{
try {
return new DefaultJavaScriptContext();
} catch (FileNotFoundException ex) {
LoggingService.DebugFormatted("Unable to create JavaScriptContext. {0}", ex);
}
return null;
}
}
}

2
src/AddIns/BackendBindings/TypeScript/Project/TypeScriptBinding.csproj

@ -87,11 +87,13 @@ @@ -87,11 +87,13 @@
<Compile Include="Src\Hosting\CompletionEntryDetailsProvider.cs" />
<Compile Include="Src\Hosting\CompletionEntryDetails.cs" />
<Compile Include="Src\Hosting\CompletionEntryDetailsResult.cs" />
<Compile Include="Src\Hosting\DefaultJavaScriptContext.cs" />
<Compile Include="Src\Hosting\DefinitionInfo.cs" />
<Compile Include="Src\Hosting\DefinitionResult.cs" />
<Compile Include="Src\Hosting\Diagnostic.cs" />
<Compile Include="Src\Hosting\DiagnosticCategory.cs" />
<Compile Include="Src\Hosting\EmitOutput.cs" />
<Compile Include="Src\Hosting\IJavaScriptContext.cs" />
<Compile Include="Src\Hosting\JsxEmit.cs" />
<Compile Include="Src\Hosting\ModuleResolutionKind.cs" />
<Compile Include="Src\Hosting\NewLineKind.cs" />

2
src/AddIns/BackendBindings/TypeScript/Test/Parsing/ParseTests.cs

@ -32,7 +32,7 @@ namespace TypeScriptBinding.Tests.Parsing @@ -32,7 +32,7 @@ namespace TypeScriptBinding.Tests.Parsing
ITypeScriptContextFactory contextFactory = MockRepository.GenerateStub<ITypeScriptContextFactory>();
contextFactory
.Stub(f => f.CreateContext())
.Return(new TypeScriptContext(scriptLoader, logger));
.Return(new TypeScriptContext(new DefaultJavaScriptContext(), scriptLoader, logger));
var parser = new TypeScriptParser(contextFactory);
ParseInfo = parser.Parse(new FileName(fileName), fileContent, null, new TypeScriptFile[0]);

Loading…
Cancel
Save