Skip to content
This repository has been archived by the owner on Dec 14, 2021. It is now read-only.

Commit

Permalink
Merge pull request #47 from CoatiSoftware/fix_trailing_comma
Browse files Browse the repository at this point in the history
Fix trailing comma
  • Loading branch information
mlangkabel authored Sep 14, 2018
2 parents 5343c7d + 6b4f6cc commit 6af009a
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 23 deletions.
1 change: 1 addition & 0 deletions SourcetrailExtension/SourcetrailExtension.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@
<ItemGroup>
<Compile Include="Multitasking\LimitedThreadsTaskScheduler.cs" />
<Compile Include="SolutionParser\CompilationDatabase.cs" />
<Compile Include="Utility\CompileCommandFileWriter.cs" />
<Compile Include="Utility\IPathResolver.cs" />
<Compile Include="SolutionParser\VsPathResolver.cs" />
<Compile Include="Utility\CompilationDatabaseSettingsList.cs" />
Expand Down
65 changes: 65 additions & 0 deletions SourcetrailExtension/Utility/CompileCommandFileWriter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2018 Coati Software KG
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

using CoatiSoftware.SourcetrailExtension.SolutionParser;

namespace CoatiSoftware.SourcetrailExtension.Utility
{
class CompileCommandFileWriter
{
private bool _isFirstCommand;
private QueuedFileWriter _fileWriter = null;

public CompileCommandFileWriter(string fileName, string targetDirectory)
{
_isFirstCommand = true;
_fileWriter = new QueuedFileWriter(fileName, targetDirectory);
}

public void PushCommand(CompileCommand command)
{
string serializedCommand = "";

if (!_isFirstCommand)
{
serializedCommand += ",\n";
}
else
{
_isFirstCommand = false;
}

foreach (string line in command.SerializeToJson().Split('\n'))
{
serializedCommand += " " + line + "\n";
}

serializedCommand = serializedCommand.TrimEnd('\n');

_fileWriter.PushMessage(serializedCommand);
}

public void StartWorking()
{
_fileWriter.StartWorking();
}

public void StopWorking()
{
_fileWriter.StopWorking();
}
}
}
2 changes: 1 addition & 1 deletion SourcetrailExtension/Utility/QueuedFileWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ private void WriteQueueToFile(ref Queue<string> messageQueue)
while (messageQueue.Count > 0)
{
_messageWrittenCount++;
writer.WriteLine(messageQueue.Dequeue());
writer.Write(messageQueue.Dequeue());
}

writer.Close();
Expand Down
26 changes: 4 additions & 22 deletions SourcetrailExtension/Wizard/WindowCreateCDB.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,31 +197,17 @@ private CreationResult CreateCdb()
return result;
}

private void CreateCompilationCommands(Utility.QueuedFileWriter fileWriter, EnvDTE.Project project, ref int projectsProcessed, bool lastProject = false)
private void CreateCompilationCommands(Utility.CompileCommandFileWriter fileWriter, EnvDTE.Project project, ref int projectsProcessed)
{
try
{
SolutionParser.SolutionParser solutionParser = new SolutionParser.SolutionParser(new VsPathResolver(_targetDir));

solutionParser.CreateCompileCommands(
project, _configurationName, _platformName, _cStandard, _additionalClangOptions, _nonSystemIncludesUseAngleBrackets,
(CompileCommand command) => {
string serializedCommand = "";
foreach (string line in command.SerializeToJson().Split('\n'))
{
serializedCommand += " " + line + "\n";
}
serializedCommand = serializedCommand.TrimEnd('\n');

fileWriter.PushMessage(serializedCommand + ",\n");
}
(CompileCommand command) => { fileWriter.PushCommand(command); }
);

if (lastProject)
{
fileWriter.PushMessage("\n");
}

lock (_lockObject)
{
projectsProcessed++;
Expand All @@ -244,7 +230,7 @@ private void CreateCompilationDatabase()
File.WriteAllText(_targetDir + "\\" + _fileName + ".json", "");
File.AppendAllText(_targetDir + "\\" + _fileName + ".json", "[\n");

Utility.QueuedFileWriter fileWriter = new Utility.QueuedFileWriter(_fileName + ".json", _targetDir);
Utility.CompileCommandFileWriter fileWriter = new Utility.CompileCommandFileWriter(_fileName + ".json", _targetDir);
fileWriter.StartWorking();

try
Expand All @@ -254,7 +240,7 @@ private void CreateCompilationDatabase()
List<Task> tasks = new List<Task>();

int projectsProcessed = 0;
foreach (EnvDTE.Project project in _projects.GetRange(0, _projects.Count - 1))
foreach (EnvDTE.Project project in _projects.GetRange(0, _projects.Count))
{
Logging.Logging.LogInfo("Scheduling project \"" + Logging.Obfuscation.NameObfuscator.GetObfuscatedName(project.Name) + "\" for parsing.");

Expand All @@ -266,12 +252,8 @@ private void CreateCompilationDatabase()
tasks.Add(task);
}

int threadCount = System.Diagnostics.Process.GetCurrentProcess().Threads.Count;

Task.WaitAll(tasks.ToArray());

CreateCompilationCommands(fileWriter, _projects[_projects.Count - 1], ref projectsProcessed, true);

fileWriter.StopWorking();

backgroundWorker1.ReportProgress(100, "Writing data to file. This might take several minutes...");
Expand Down

0 comments on commit 6af009a

Please sign in to comment.