Skip to content
This repository has been archived by the owner on Nov 9, 2019. It is now read-only.

Commit

Permalink
Undo impl of static v8engine and add ScriptSnapshot #5 #8
Browse files Browse the repository at this point in the history
This commit withdraw's changes that were introduced do to an false assumption
about TypeScriptContext.cs.
We removed V8TypescriptProvider.cs and placed the V8Engine back to the
TypeScriptContext.cs to restore the old behavior.

To not to introduce V8Engine into the Typescript-addin we added a new
interace (IScriptSnapshotExtension) which adds properties to
IScriptSnapshot. The properties are needed to compare the changes from
an old and current snapshot.
  • Loading branch information
chrisber committed Mar 15, 2015
1 parent 2ffb185 commit b363119
Show file tree
Hide file tree
Showing 13 changed files with 139 additions and 86 deletions.
19 changes: 13 additions & 6 deletions src/TypeScriptBinding/Hosting/LanguageServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,20 @@ public string[] getScriptFileNames()
return scripts.Select(keyPair => keyPair.Value.FileName).ToArray();
}
public string getScriptVersion(string fileName)
{
return scripts[fileName].Version.ToString();
{
Script script;
if(this.scripts.TryGetValue(fileName, out script)){
return scripts[fileName].Version.ToString();
}
return null;
}
public IScriptSnapshot getScriptSnapshot(string fileName)
{
Script script = scripts[fileName];
return new ScriptSnapshot(logger, script);
public IScriptSnapshot getScriptSnapshot(string fileName)
{
Script script;
if(this.scripts.TryGetValue(fileName, out script)){
return new ScriptSnapshot(logger, script);
}
return null;
}
public string getLocalizedDiagnosticMessages()
{
Expand Down
30 changes: 16 additions & 14 deletions src/TypeScriptBinding/Hosting/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,26 +64,28 @@ public string FileName {

public int[] GetLineStartPositions()
{
if (lineStartPositions.Count == 0) {
string[] lines = Source.Split('\r');
lineStartPositions.Add(0);
int position = 0;
for (int i = 0; i < lines.Length; ++i) {
position += lines[i].Length + 2;
lineStartPositions.Add(position);
}
}
//TODO Where do we need this?
// if (lineStartPositions.Count == 0) {
// string[] lines;
// if(Environment.NewLine == "\n"){
// lines = Source.Split('\n');
// }else{
// lines = Source.Split('\r');
// }
//
// lineStartPositions.Add(0);
// int position = 0;
// for (int i = 0; i < lines.Length; ++i) {
// position += lines[i].Length + 2;
// lineStartPositions.Add(position);
// }
// }

return lineStartPositions.ToArray();
}

public TextChangeRange GetTextChangeRange(IScriptSnapshot oldSnapshot)
{
//@TODO calculate TextChangeRange
// this is used by getScriptSnapshot
// should this be implemented in v8 to prevent
// function call's?

TextSpan tSpan = new TextSpan();
tSpan.start = 0;
tSpan.length = oldSnapshot.getLength();
Expand Down
32 changes: 31 additions & 1 deletion src/TypeScriptBinding/Hosting/ScriptSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,23 @@

namespace ICSharpCode.TypeScriptBinding.Hosting
{
public class ScriptSnapshot : IScriptSnapshot
public class ScriptSnapshot : IScriptSnapshotExtension
{
ILogger logger;
Script script;

string source;
int version;
int[] positions;

public ScriptSnapshot(ILogger logger, Script script)
{
this.logger = logger;
this.script = script;

this.source = script.Source;
this.version = script.Version;
this.positions = script.GetLineStartPositions();
}

public string getText(int start, int end)
Expand Down Expand Up @@ -80,5 +88,27 @@ void Log(string format, params object[] args)
{
logger.log(String.Format(format, args));
}


#region IScriptSnapshotExtension
public string ScriptSource {
get {
return this.source;
}
}

public int[] LineStartPositions {
get {
return this.positions;
}
}

public int ScriptVersion {
get {
return this.version;
}
}
#endregion

}
}
54 changes: 38 additions & 16 deletions src/TypeScriptBinding/Hosting/TypeScriptContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ namespace ICSharpCode.TypeScriptBinding.Hosting
{
public class TypeScriptContext : IDisposable
{
TypeScriptLanguageServices context;
IScriptLoader scriptLoader;
LanguageServiceHost host = null;
LanguageServiceHost host;
bool runInitialization = true;

public TypeScriptContext(IScriptLoader scriptLoader, ILogger logger)
{
this.scriptLoader = scriptLoader;

host = (LanguageServiceHost) V8TypescriptProvider.TService().Host;
this.host = new LanguageServiceHost(logger);
this.context = new TypeScriptLanguageServices(host,scriptLoader.GetTypeScriptServicesScript());

host.AddDefaultLibScript(new FilePath(scriptLoader.LibScriptFileName), scriptLoader.GetLibScript());
}
Expand All @@ -61,7 +63,7 @@ public CompletionInfo GetCompletionItems(FilePath fileName, int offset, string t
host.UpdateFileName(fileName);
host.isMemberCompletion = memberCompletion;

return V8TypescriptProvider.TService().GetCompletionsAtPosition(fileName,offset);
return context.GetCompletionsAtPosition(fileName,offset);
}

public CompletionEntryDetails GetCompletionEntryDetails(FilePath fileName, int offset, string entryName)
Expand All @@ -70,66 +72,86 @@ public CompletionEntryDetails GetCompletionEntryDetails(FilePath fileName, int o
host.UpdateFileName(fileName);
host.completionEntry = entryName;

return V8TypescriptProvider.TService().GetCompletionEntryDetails(fileName, offset, entryName);
return context.GetCompletionEntryDetails(fileName, offset, entryName);
}

public SignatureHelpItems GetSignature(FilePath fileName, int offset)
{
host.position = offset;
host.UpdateFileName(fileName);

return V8TypescriptProvider.TService().GetSignatureHelpItems(fileName, offset);
return context.GetSignatureHelpItems(fileName, offset);
}

public ReferenceEntry[] FindReferences(FilePath fileName, int offset)
{
host.position = offset;
host.UpdateFileName(fileName);

return V8TypescriptProvider.TService().GetReferencesAtPosition(fileName, offset);
return context.GetReferencesAtPosition(fileName, offset);
}

public DefinitionInfo[] GetDefinition(FilePath fileName, int offset)
{
host.position = offset;
host.UpdateFileName(fileName);

return V8TypescriptProvider.TService().GetDefinitionAtPosition(fileName, offset);
return context.GetDefinitionAtPosition(fileName, offset);
}

public NavigationBarItem[] GetNavigationInfo(FilePath fileName)
{
host.UpdateFileName(fileName);
return V8TypescriptProvider.TService().GetNavigationBarItems(fileName);
return context.GetNavigationBarItems(fileName);
}

public EmitOutput Compile(FilePath fileName, ICompilerOptions options)
{
host.UpdateCompilerSettings(options);
host.UpdateFileName(fileName);

return V8TypescriptProvider.TService().GetEmitOutput(fileName);
return context.GetEmitOutput(fileName);
}

public Diagnostic[] GetDiagnostics(FilePath fileName, ICompilerOptions options)
{
host.UpdateCompilerSettings(options);
host.UpdateFileName(fileName);

var syntactic = V8TypescriptProvider.TService().GetSyntacticDiagnostics(fileName);
var semantic = V8TypescriptProvider.TService().GetSemanticDiagnostics(fileName);
var syntactic = context.GetSyntacticDiagnostics(fileName);
var semantic = context.GetSemanticDiagnostics(fileName);
var result = semantic.Concat(syntactic).ToArray();
return result;
}

public void Dispose()
{
//context._dispose();
}

#endregion


#region LanguageServiceHostEnvironment calls
public void Dispose()
{
// context.Dispose();
}

public void GetCompletionItemsForTheFirstTime()
{
// HACK - run completion on first file so the user does not have to wait about
// 1-2 seconds for the completion list to appear the first time it is triggered.
string fileName = host.GetFileNames().FirstOrDefault();
if (fileName != null) {
GetCompletionItems(fileName, 1, String.Empty, false);
}
}

public void RunInitialisationScript()
{
if (runInitialization) {
runInitialization = false;
context.CleanupSemanticCache();
}
}


public void AddFile(FilePath fileName, string text)
{
Expand Down
7 changes: 6 additions & 1 deletion src/TypeScriptBinding/Hosting/TypeScriptContextProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ public TypeScriptContext CreateContext(FilePath fileName, string text)
{
TypeScriptContext context = factory.CreateContext();
context.AddFile(fileName, text);
context.RunInitialisationScript();
context.GetCompletionItemsForTheFirstTime();

cachedContexts.Add(fileName, context);

Expand Down Expand Up @@ -100,7 +102,10 @@ public TypeScriptContext CreateProjectContext(TypeScriptProject project)
foreach (FilePath typeScriptFileName in project.GetTypeScriptFileNames()) {
AddFileToProjectContext(context, typeScriptFileName);
}


context.RunInitialisationScript();
context.GetCompletionItemsForTheFirstTime();

return context;
}

Expand Down
20 changes: 0 additions & 20 deletions src/TypeScriptBinding/Hosting/V8TypescriptProvider.cs

This file was deleted.

32 changes: 22 additions & 10 deletions src/TypeScriptBinding/TypeScriptBinding.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,18 @@
<DefineConstants>TRACE</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<CustomCommands>
<CustomCommands>
<Command type="Execute" command="/usr/lib/monodevelop/bin/MonoDevelop.exe" workingdir="/usr/lib/monodevelop/bin/">
<EnvironmentVariables>
<Variable name="MONODEVELOP_DEV_ADDINS" value="${TargetDir}" />
</EnvironmentVariables>
</Command>
</CustomCommands>
</CustomCommands>
<CustomCommands>
<CustomCommands>
<Command type="Execute"
command="/usr/lib/monodevelop/bin/MonoDevelop.exe"
workingdir="/usr/lib/monodevelop/bin/">
<EnvironmentVariables>
<Variable name="MONODEVELOP_DEV_ADDINS" value="${TargetDir}" />
</EnvironmentVariables>
</Command>
</CustomCommands>
</CustomCommands>
<Externalconsole>true</Externalconsole>
</PropertyGroup>
<ItemGroup>
<Reference Include="ICSharpCode.NRefactory">
Expand Down Expand Up @@ -164,7 +167,6 @@
<Compile Include="Hosting\EmitReturnStatus.cs" />
<Compile Include="Hosting\CompletionEntryDetailsProvider.cs" />
<Compile Include="Hosting\ScriptSnapshot.cs" />
<Compile Include="Hosting\V8TypescriptProvider.cs" />
<Compile Include="Hosting\LanguageServiceHost.cs" />
<Compile Include="Hosting\NavigateToItemRegion.cs" />
<Compile Include="Hosting\NavigationBarItemRegion.cs" />
Expand Down Expand Up @@ -208,4 +210,14 @@
<Name>TypeScriptLanguageService</Name>
</ProjectReference>
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
<Properties>
<Policies>
<TextStylePolicy FileWidth="120" TabsToSpaces="False" EolMarker="Unix" inheritsSet="VisualStudio" inheritsScope="text/plain" scope="text/x-csharp" />
<CSharpFormattingPolicy IndentSwitchBody="True" BeforeMethodDeclarationParentheses="False" BeforeMethodCallParentheses="False" BeforeConstructorDeclarationParentheses="False" NewLineBeforeConstructorInitializerColon="NewLine" NewLineAfterConstructorInitializerColon="SameLine" BeforeDelegateDeclarationParentheses="False" NewParentheses="False" SpacesBeforeBrackets="False" inheritsSet="Mono" inheritsScope="text/x-csharp" scope="text/x-csharp" />
</Policies>
</Properties>
</MonoDevelop>
</ProjectExtensions>
</Project>
12 changes: 6 additions & 6 deletions src/TypeScriptBinding/TypeScriptOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ public TypeScriptOptions()
this.cOpt.charset="UTF-8";
this.cOpt.codepage=0;
this.cOpt.declaration=false;
this.cOpt.diagnostics=false;
this.cOpt.diagnostics=true;
this.cOpt.emitBOM=false;
this.cOpt.help=false;
this.cOpt.listFiles=false;
this.cOpt.locale="";
this.cOpt.mapRoot="";
this.cOpt.module=0;
this.cOpt.noEmit=false;
this.cOpt.noEmitOnError=false;
this.cOpt.noErrorTruncation=false;
this.cOpt.noImplicitAny=false;
this.cOpt.noEmit=true;
this.cOpt.noEmitOnError=true;
this.cOpt.noErrorTruncation=true;
this.cOpt.noImplicitAny=true;
this.cOpt.noLib=false;
this.cOpt.noLibCheck=false;
this.cOpt.noResolve=false;
Expand All @@ -63,7 +63,7 @@ public TypeScriptOptions()
this.cOpt.preserveConstEnums=false;
this.cOpt.project="";
this.cOpt.removeComments=false;
this.cOpt.sourceMap=false;
this.cOpt.sourceMap=true;
this.cOpt.sourceRoot="";
this.cOpt.suppressImplicitAnyIndexErrors=false;
this.cOpt.target=ScriptTarget.ES6;
Expand Down
2 changes: 1 addition & 1 deletion src/TypeScriptBinding/TypeScriptParsedDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ Error CreateError(Diagnostic diagnostic, IDocument document)
TextLocation location = document.GetLocation(diagnostic.start);
return new Error(
GetErrorType(diagnostic.category),
diagnostic.ToString(),
diagnostic.messageText,
location);
}

Expand Down
Loading

0 comments on commit b363119

Please sign in to comment.