Skip to content
This repository was archived by the owner on Oct 16, 2020. It is now read-only.

Commit 70cf4bf

Browse files
committed
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
1 parent 7c27bb2 commit 70cf4bf

File tree

6 files changed

+133
-8
lines changed

6 files changed

+133
-8
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) 2015 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
using Noesis.Javascript;
21+
22+
namespace ICSharpCode.TypeScriptBinding.Hosting
23+
{
24+
public class DefaultJavaScriptContext : IJavaScriptContext
25+
{
26+
readonly JavascriptContext context = new JavascriptContext();
27+
28+
public void SetParameter(string name, object value)
29+
{
30+
context.SetParameter(name, value);
31+
}
32+
33+
public void Run(string script)
34+
{
35+
context.Run(script);
36+
}
37+
38+
public void Dispose()
39+
{
40+
context.Dispose();
41+
}
42+
}
43+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright (c) 2015 AlphaSierraPapa for the SharpDevelop Team
2+
//
3+
// Permission is hereby granted, free of charge, to any person obtaining a copy of this
4+
// software and associated documentation files (the "Software"), to deal in the Software
5+
// without restriction, including without limitation the rights to use, copy, modify, merge,
6+
// publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons
7+
// to whom the Software is furnished to do so, subject to the following conditions:
8+
//
9+
// The above copyright notice and this permission notice shall be included in all copies or
10+
// substantial portions of the Software.
11+
//
12+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
14+
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
15+
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
17+
// DEALINGS IN THE SOFTWARE.
18+
19+
using System;
20+
21+
namespace ICSharpCode.TypeScriptBinding.Hosting
22+
{
23+
public interface IJavaScriptContext : IDisposable
24+
{
25+
void SetParameter(string name, object value);
26+
void Run(string script);
27+
}
28+
}

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

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,24 +39,30 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
3939
{
4040
public class TypeScriptContext : IDisposable
4141
{
42-
JavascriptContext context = new JavascriptContext();
42+
IJavaScriptContext context;
4343
LanguageServiceShimHost host;
4444
TypeScriptProject project;
4545
IScriptLoader scriptLoader;
4646
bool runInitialization = true;
4747

48-
public TypeScriptContext(IScriptLoader scriptLoader, ILogger logger)
48+
public TypeScriptContext(IJavaScriptContext context, IScriptLoader scriptLoader, ILogger logger)
4949
{
50+
this.context = context;
5051
this.scriptLoader = scriptLoader;
5152
host = new LanguageServiceShimHost(logger);
5253
host.AddDefaultLibScript(new FileName(scriptLoader.LibScriptFileName), scriptLoader.GetLibScript());
53-
context.SetParameter("host", host);
54-
context.Run(scriptLoader.GetTypeScriptServicesScript());
54+
55+
if (context != null) {
56+
context.SetParameter("host", host);
57+
context.Run(scriptLoader.GetTypeScriptServicesScript());
58+
}
5559
}
5660

5761
public void Dispose()
5862
{
59-
context.Dispose();
63+
if (context != null) {
64+
context.Dispose();
65+
}
6066
}
6167

6268
public void AddFile(FileName fileName, string text)
@@ -68,7 +74,9 @@ public void RunInitialisationScript()
6874
{
6975
if (runInitialization) {
7076
runInitialization = false;
71-
context.Run(scriptLoader.GetMainScript());
77+
if (context != null) {
78+
context.Run(scriptLoader.GetMainScript());
79+
}
7280
}
7381
}
7482

@@ -89,6 +97,9 @@ public void UpdateFile(FileName fileName, string text)
8997

9098
public CompletionInfo GetCompletionItems(FileName fileName, int offset, string text, bool memberCompletion)
9199
{
100+
if (context == null)
101+
return new CompletionInfo();
102+
92103
UpdateCompilerSettings();
93104
host.position = offset;
94105
host.UpdateFileName(fileName);
@@ -101,6 +112,9 @@ public CompletionInfo GetCompletionItems(FileName fileName, int offset, string t
101112

102113
public CompletionEntryDetails GetCompletionEntryDetails(FileName fileName, int offset, string entryName)
103114
{
115+
if (context == null)
116+
return new CompletionEntryDetails();
117+
104118
UpdateCompilerSettings();
105119
host.position = offset;
106120
host.UpdateFileName(fileName);
@@ -113,6 +127,9 @@ public CompletionEntryDetails GetCompletionEntryDetails(FileName fileName, int o
113127

114128
public SignatureHelpItems GetSignature(FileName fileName, int offset)
115129
{
130+
if (context == null)
131+
return new SignatureHelpItems();
132+
116133
UpdateCompilerSettings();
117134
host.position = offset;
118135
host.UpdateFileName(fileName);
@@ -124,6 +141,9 @@ public SignatureHelpItems GetSignature(FileName fileName, int offset)
124141

125142
public ReferenceEntry[] FindReferences(FileName fileName, int offset)
126143
{
144+
if (context == null)
145+
return new ReferenceEntry[0];
146+
127147
UpdateCompilerSettings();
128148
host.position = offset;
129149
host.UpdateFileName(fileName);
@@ -135,6 +155,9 @@ public ReferenceEntry[] FindReferences(FileName fileName, int offset)
135155

136156
public DefinitionInfo[] GetDefinition(FileName fileName, int offset)
137157
{
158+
if (context == null)
159+
return new DefinitionInfo[0];
160+
138161
UpdateCompilerSettings();
139162
host.position = offset;
140163
host.UpdateFileName(fileName);
@@ -146,6 +169,9 @@ public DefinitionInfo[] GetDefinition(FileName fileName, int offset)
146169

147170
public NavigationBarItem[] GetNavigationInfo(FileName fileName)
148171
{
172+
if (context == null)
173+
return new NavigationBarItem[0];
174+
149175
UpdateCompilerSettings();
150176
host.UpdateFileName(fileName);
151177
context.Run(scriptLoader.GetNavigationScript());
@@ -160,6 +186,9 @@ public void RemoveFile(FileName fileName)
160186

161187
public EmitOutput Compile(FileName fileName, ITypeScriptOptions options)
162188
{
189+
if (context == null)
190+
return new EmitOutput();
191+
163192
host.UpdateCompilerSettings(options);
164193
host.UpdateFileName(fileName);
165194
context.Run(scriptLoader.GetLanguageServicesCompileScript());
@@ -169,6 +198,9 @@ public EmitOutput Compile(FileName fileName, ITypeScriptOptions options)
169198

170199
public Diagnostic[] GetDiagnostics(FileName fileName, ITypeScriptOptions options)
171200
{
201+
if (context == null)
202+
return new [] { GetMicrosoftRuntimeNotInstalledDiagnostic() };
203+
172204
host.UpdateCompilerSettings(options);
173205
host.UpdateFileName(fileName);
174206
context.Run(scriptLoader.GetDiagnosticsScript());
@@ -196,5 +228,13 @@ void UpdateCompilerSettings()
196228
host.UpdateCompilerSettings(project);
197229
}
198230
}
231+
232+
Diagnostic GetMicrosoftRuntimeNotInstalledDiagnostic()
233+
{
234+
return new Diagnostic {
235+
category = DiagnosticCategory.Error,
236+
message = "Microsoft Visual C++ 2010 Redistributable Package is not installed. https://www.microsoft.com/en-us/download/details.aspx?id=5555"
237+
};
238+
}
199239
}
200240
}

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
//
2828

2929
using System;
30+
using System.IO;
31+
using ICSharpCode.Core;
3032

3133
namespace ICSharpCode.TypeScriptBinding.Hosting
3234
{
@@ -48,7 +50,17 @@ public TypeScriptContextFactory(IScriptLoader scriptLoader, ILogger logger)
4850

4951
public TypeScriptContext CreateContext()
5052
{
51-
return new TypeScriptContext(scriptLoader, logger);
53+
return new TypeScriptContext(CreateJavaScriptContext(), scriptLoader, logger);
54+
}
55+
56+
IJavaScriptContext CreateJavaScriptContext()
57+
{
58+
try {
59+
return new DefaultJavaScriptContext();
60+
} catch (FileNotFoundException ex) {
61+
LoggingService.DebugFormatted("Unable to create JavaScriptContext. {0}", ex);
62+
}
63+
return null;
5264
}
5365
}
5466
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,13 @@
8787
<Compile Include="Src\Hosting\CompletionEntryDetailsProvider.cs" />
8888
<Compile Include="Src\Hosting\CompletionEntryDetails.cs" />
8989
<Compile Include="Src\Hosting\CompletionEntryDetailsResult.cs" />
90+
<Compile Include="Src\Hosting\DefaultJavaScriptContext.cs" />
9091
<Compile Include="Src\Hosting\DefinitionInfo.cs" />
9192
<Compile Include="Src\Hosting\DefinitionResult.cs" />
9293
<Compile Include="Src\Hosting\Diagnostic.cs" />
9394
<Compile Include="Src\Hosting\DiagnosticCategory.cs" />
9495
<Compile Include="Src\Hosting\EmitOutput.cs" />
96+
<Compile Include="Src\Hosting\IJavaScriptContext.cs" />
9597
<Compile Include="Src\Hosting\JsxEmit.cs" />
9698
<Compile Include="Src\Hosting\ModuleResolutionKind.cs" />
9799
<Compile Include="Src\Hosting\NewLineKind.cs" />

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public void Parse(string text, string fileName = @"d:\projects\MyProject\test.ts
3232
ITypeScriptContextFactory contextFactory = MockRepository.GenerateStub<ITypeScriptContextFactory>();
3333
contextFactory
3434
.Stub(f => f.CreateContext())
35-
.Return(new TypeScriptContext(scriptLoader, logger));
35+
.Return(new TypeScriptContext(new DefaultJavaScriptContext(), scriptLoader, logger));
3636

3737
var parser = new TypeScriptParser(contextFactory);
3838
ParseInfo = parser.Parse(new FileName(fileName), fileContent, null, new TypeScriptFile[0]);

0 commit comments

Comments
 (0)