Skip to content

Commit aa6a7f7

Browse files
Created copy of array
Fixed #179
1 parent c4df9b5 commit aa6a7f7

File tree

6 files changed

+52
-33
lines changed

6 files changed

+52
-33
lines changed

src/WebCompiler/Config/ConfigFileProcessor.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,12 @@ private IEnumerable<CompilerResult> SourceFileChanged(string configFile,
116116
var dependencies = DependencyService.GetDependencies(projectPath, sourceFile);
117117
if(dependencies != null)
118118
{
119-
if(dependencies.ContainsKey(sourceFile.ToLowerInvariant()))
119+
string key = sourceFile.ToLowerInvariant();
120+
121+
if (dependencies.ContainsKey(key))
120122
{
121123
//compile all files that have references to the compiled file
122-
foreach (var file in dependencies[sourceFile.ToLowerInvariant()].DependentFiles)
124+
foreach (var file in dependencies[key].DependentFiles.ToArray())
123125
{
124126
if (!compiledFiles.Contains(file.ToLowerInvariant()))
125127
SourceFileChanged(configFile, file, projectPath, compiledFiles);

src/WebCompiler/Dependencies/Dependencies.cs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,40 +11,14 @@ namespace WebCompiler
1111
/// </summary>
1212
public class Dependencies
1313
{
14-
private HashSet<string> _dependentOn;
15-
private HashSet<string> _dependentFiles;
16-
1714
/// <summary>
1815
/// Contains all files the current file is dependent ont
1916
/// </summary>
20-
public HashSet<string> DependentOn
21-
{
22-
get
23-
{
24-
return _dependentOn;
25-
}
26-
set
27-
{
28-
_dependentOn = value;
29-
}
30-
}
17+
public HashSet<string> DependentOn { get; set; } = new HashSet<string>();
3118

3219
/// <summary>
3320
/// Contains all files that are dependent on this file
3421
/// </summary>
35-
public HashSet<string> DependentFiles
36-
{
37-
get { return _dependentFiles; }
38-
set { _dependentFiles = value; }
39-
}
40-
41-
/// <summary>
42-
/// Creates a new dependecies object
43-
/// </summary>
44-
public Dependencies()
45-
{
46-
_dependentOn = new HashSet<string>();
47-
_dependentFiles = new HashSet<string>();
48-
}
22+
public HashSet<string> DependentFiles { get; set; } = new HashSet<string>();
4923
}
5024
}

src/WebCompiler/Dependencies/DependencyResolverBase.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ public abstract string[] SearchPatterns
3030
get;
3131
}
3232

33+
/// <summary>
34+
/// The file extension of files of this type
35+
/// </summary>
36+
public abstract string FileExtension
37+
{
38+
get;
39+
}
40+
3341
/// <summary>
3442
/// Gets the dependency tree
3543
/// </summary>

src/WebCompiler/Dependencies/LessDependencyResolver.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,14 @@ public override string[] SearchPatterns
66
{
77
get { return new string[] { "*.less" }; }
88
}
9+
10+
public override string FileExtension
11+
{
12+
get
13+
{
14+
return ".less";
15+
}
16+
}
17+
918
}
1019
}

src/WebCompiler/Dependencies/SassDependencyResolver.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using System.Collections.Generic;
1+
using System;
2+
using System.Collections.Generic;
23
using System.IO;
34

45
namespace WebCompiler
@@ -10,6 +11,15 @@ public override string[] SearchPatterns
1011
get { return new[] { "*.scss", "*.sass" }; }
1112
}
1213

14+
public override string FileExtension
15+
{
16+
get
17+
{
18+
return ".scss";
19+
}
20+
}
21+
22+
1323
/// <summary>
1424
/// Updates the dependencies of a single file
1525
/// </summary>
@@ -28,7 +38,7 @@ public override void UpdateFileDependencies(string path)
2838
//remove the dependentfile registration of this file for all other files
2939
foreach (var dependenciesPath in Dependencies.Keys)
3040
{
31-
var lowerDependenciesPath = path.ToLowerInvariant();
41+
var lowerDependenciesPath = dependenciesPath.ToLowerInvariant();
3242
if (Dependencies[lowerDependenciesPath].DependentFiles.Contains(path))
3343
{
3444
Dependencies[lowerDependenciesPath].DependentFiles.Remove(path);
@@ -43,6 +53,12 @@ public override void UpdateFileDependencies(string path)
4353
foreach (System.Text.RegularExpressions.Match match in matches)
4454
{
4555
FileInfo importedfile = new FileInfo(Path.Combine(info.DirectoryName, match.Groups[3].Value));
56+
//if the file doesn't end with the correct extension, an import statement without extension is probably used, to re-add the extension (#175)
57+
if (string.Compare(importedfile.Extension, FileExtension, StringComparison.OrdinalIgnoreCase) != 0)
58+
{
59+
importedfile = new FileInfo(importedfile.FullName + this.FileExtension);
60+
}
61+
4662
var dependencyFilePath = importedfile.FullName.ToLowerInvariant();
4763

4864
if (!Dependencies[path].DependentOn.Contains(dependencyFilePath))

src/WebCompilerVsix/Helpers/ProjectHelpers.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static IEnumerable<string> GetSelectedItemPaths()
5858

5959
public static string GetRootFolder(this Project project)
6060
{
61-
if (string.IsNullOrEmpty(project.FullName))
61+
if (project == null || string.IsNullOrEmpty(project.FullName))
6262
return null;
6363

6464
string fullPath;
@@ -222,6 +222,16 @@ public static Project GetActiveProject()
222222

223223
if (activeSolutionProjects != null && activeSolutionProjects.Length > 0)
224224
return activeSolutionProjects.GetValue(0) as Project;
225+
226+
var doc = _dte.ActiveDocument;
227+
228+
if (doc != null && !string.IsNullOrEmpty(doc.FullName))
229+
{
230+
var item = _dte.Solution?.FindProjectItem(doc.FullName);
231+
232+
if (item != null)
233+
return item.ContainingProject;
234+
}
225235
}
226236
catch (Exception ex)
227237
{

0 commit comments

Comments
 (0)