use file id instead of file path in recorded locations
This commit is contained in:
@@ -77,7 +77,7 @@ name.nameElements.push_back(parentElement);
|
||||
|
||||
sourcetrail::NameElement childElement;
|
||||
childElement.prefix = "void"; // tooltips omit prefixes of parents and only show the prefix of the hovered element
|
||||
childElement.name = "bar";
|
||||
childElement.name = "bar";
|
||||
childElement.postfix = "()"; // tooltips omit postfixes of parents and only show the prefix of the hovered element
|
||||
name.nameElements.push_back(childElement);
|
||||
|
||||
@@ -97,14 +97,16 @@ writer.close();
|
||||
sourcetrail::SourcetrailDBWriter writer;
|
||||
writer.open("MyProject.srctrldb");
|
||||
|
||||
int symbolId = writer.recordSymbol({ "::",{ { "", "Bar", "" },{ "void", "bar", "()" } } });
|
||||
|
||||
int fileId = writer.recordFile("C:/example/Bar.cpp"); // path to the source file that contains the recorded location
|
||||
|
||||
sourcetrail::SourceRange location;
|
||||
location.filePath = "C:/example/Bar.cpp"; // path to the source file that contains the recorded location
|
||||
location.fileId = fileId;
|
||||
location.startLine = 8; // recorded lines start at 1, not 0
|
||||
location.startColumn = 7; // recorded columns start at 1, not 0
|
||||
location.endLine = 8;
|
||||
location.endColumn = 9;
|
||||
|
||||
int symbolId = writer.recordSymbol({ "::",{ { "", "Bar", "" }, { "void", "bar", "()" } } });
|
||||
writer.recordSymbolLocation(symbolId, location); // lets you click symbols in Sourcetrail's code view
|
||||
|
||||
writer.close();
|
||||
@@ -122,7 +124,8 @@ writer.open("MyProject.srctrldb");
|
||||
int contextSymbolId = writer.recordSymbol({ "::",{ { "", "Bar", "" },{ "void", "bar", "()" } } });
|
||||
int referencedSymbolId = writer.recordSymbol({ "::",{ { "void", "foo", "()" } } });
|
||||
int referenceId = writer.recordReference(contextSymbolId, referencedSymbolId, sourcetrail::REFERENCE_CALL); // edges always go from the context to the referenced symbol
|
||||
writer.recordReferenceLocation(referenceId, { "C:/example/Bar.cpp", 10, 3, 10, 5 }); // clicking an edge will highlight this locaion in the code view
|
||||
int fileId = writer.recordFile("C:/example/Bar.cpp");
|
||||
writer.recordReferenceLocation(referenceId, { fileId, 10, 3, 10, 5 }); // clicking an edge will highlight this locaion in the code view
|
||||
|
||||
writer.close();
|
||||
```
|
||||
@@ -136,8 +139,8 @@ writer.close();
|
||||
sourcetrail::SourcetrailDBWriter writer;
|
||||
writer.open("MyProject.srctrldb");
|
||||
|
||||
int fileId = writer.recordFile("C:/example/Bar.cpp"); // files are stored implicitly when recording locations, but this call provides an id
|
||||
int referencedSymbolId = writer.recordFileLanguage(fileId, "cpp"); // this enables syntax highlighting
|
||||
int fileId = writer.recordFile("C:/example/Bar.cpp");
|
||||
int referencedSymbolId = writer.recordFileLanguage(fileId, "cpp"); // this enables syntax highlighting for predefined languages
|
||||
|
||||
writer.close();
|
||||
```
|
||||
@@ -152,8 +155,9 @@ sourcetrail::SourcetrailDBWriter writer;
|
||||
writer.open("MyProject.srctrldb");
|
||||
|
||||
int id = writer.recordLocalSymbol("some_unique_name"); // this name is just for referencing the symbol and won't be displayed anywhere
|
||||
writer.recordLocalSymbolLocation(id, { "C:/example/Foo.cpp", 3, 6, 3, 6 });
|
||||
writer.recordLocalSymbolLocation(id, { "C:/example/Foo.cpp", 4, 2, 4, 2 });
|
||||
int fileId = writer.recordFile("C:/example/Foo.cpp");
|
||||
writer.recordLocalSymbolLocation(id, { fileId, 3, 6, 3, 6 });
|
||||
writer.recordLocalSymbolLocation(id, { fileId, 4, 2, 4, 2 });
|
||||
|
||||
writer.close();
|
||||
```
|
||||
@@ -167,7 +171,8 @@ writer.close();
|
||||
sourcetrail::SourcetrailDBWriter writer;
|
||||
writer.open("MyProject.srctrldb");
|
||||
|
||||
int id = writer.recordCommentLocation({ "C:/example/Bar.cpp", 3, 2, 7, 4 }); // causes Sourcetrail to treat the source range as atomic - either display it completely or don't show it at all
|
||||
int fileId = writer.recordFile("C:/example/Bar.cpp");
|
||||
int id = writer.recordCommentLocation({ fileId, 3, 2, 7, 4 }); // causes Sourcetrail to treat the source range as atomic - either display it completely or don't show it at all
|
||||
|
||||
writer.close();
|
||||
```
|
||||
@@ -181,9 +186,10 @@ writer.close();
|
||||
sourcetrail::SourcetrailDBWriter writer;
|
||||
writer.open("MyProject.srctrldb");
|
||||
|
||||
int fileId = writer.recordFile("C:/example/Foo.cpp");
|
||||
std::string message = "Really? You missed that \";\" again?";
|
||||
bool fatal = false;
|
||||
sourcetrail::SourceRange location = { "C:/example/Foo.cpp", 4, 4, 4, 4 };
|
||||
sourcetrail::SourceRange location = { fileId, 4, 4, 4, 4 };
|
||||
int id = writer.recordError(message, fatal, location); // store and show parsing and indexing errors
|
||||
|
||||
writer.close();
|
||||
|
||||
@@ -37,7 +37,6 @@ set(LIB_HDR_FILES
|
||||
include/NameHierarchy.h
|
||||
include/NodeKind.h
|
||||
include/ReferenceKind.h
|
||||
include/SourceLocation.h
|
||||
include/SourceRange.h
|
||||
include/SourcetrailDBWriter.h
|
||||
include/SourcetrailException.h
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#ifndef SOURCETRAIL_SOURCE_LOCATION_H
|
||||
#define SOURCETRAIL_SOURCE_LOCATION_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace sourcetrail
|
||||
{
|
||||
/**
|
||||
* Struct that represents a single character location in a source file.
|
||||
*
|
||||
* Note: Line and column numbers start at 1 instead of 0!
|
||||
*/
|
||||
struct SourceLocation
|
||||
{
|
||||
std::string filePath;
|
||||
int line;
|
||||
int column;
|
||||
};
|
||||
}
|
||||
|
||||
#endif // SOURCETRAIL_SOURCE_LOCATION_H
|
||||
@@ -17,18 +17,17 @@
|
||||
#ifndef SOURCETRAIL_SOURCE_RANGE_H
|
||||
#define SOURCETRAIL_SOURCE_RANGE_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace sourcetrail
|
||||
{
|
||||
/**
|
||||
* Struct that represents the location of a range of characters in a source file.
|
||||
*
|
||||
* Note: Line and column numbers start at 1 instead of 0!
|
||||
* Note: The SourceRange includes both, the start and the end column number.
|
||||
*/
|
||||
struct SourceRange
|
||||
{
|
||||
std::string filePath;
|
||||
int fileId;
|
||||
int startLine;
|
||||
int startColumn;
|
||||
int endLine;
|
||||
|
||||
@@ -199,7 +199,7 @@ namespace sourcetrail
|
||||
|
||||
const std::vector<std::string> tableNames = {
|
||||
"meta",
|
||||
"error"
|
||||
"error",
|
||||
"component_access",
|
||||
"occurrence",
|
||||
"source_location",
|
||||
|
||||
@@ -550,9 +550,8 @@ namespace sourcetrail
|
||||
|
||||
try
|
||||
{
|
||||
const int fileId = addFile(location.filePath);
|
||||
const int sourceLocationId = m_storage->addSourceLocation(StorageSourceLocationData(
|
||||
fileId,
|
||||
location.fileId,
|
||||
location.startLine,
|
||||
location.startColumn,
|
||||
location.endLine,
|
||||
@@ -724,10 +723,8 @@ namespace sourcetrail
|
||||
|
||||
void SourcetrailDBWriter::addSourceLocation(int elementId, const SourceRange& location, LocationKind kind)
|
||||
{
|
||||
const int fileId = addFile(location.filePath);
|
||||
|
||||
const int sourceLocationId = m_storage->addSourceLocation(StorageSourceLocationData(
|
||||
fileId,
|
||||
location.fileId,
|
||||
location.startLine,
|
||||
location.startColumn,
|
||||
location.endLine,
|
||||
|
||||
+14
-9
@@ -117,6 +117,7 @@ namespace sourcetrail
|
||||
SECTION("writer records symbol locations")
|
||||
{
|
||||
const std::string filePath = "path/to/non_existing_file.cpp";
|
||||
const int fileId = writer.recordFile(filePath);
|
||||
const int startLine = 1;
|
||||
const int startCol = 2;
|
||||
const int endLine = 3;
|
||||
@@ -128,7 +129,7 @@ namespace sourcetrail
|
||||
{
|
||||
const bool success = writer.recordSymbolLocation(
|
||||
idSymbol1,
|
||||
SourceRange({ filePath, startLine, startCol, endLine, endCol })
|
||||
{ fileId, startLine, startCol, endLine, endCol }
|
||||
);
|
||||
REQUIRE(success);
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
@@ -142,7 +143,7 @@ namespace sourcetrail
|
||||
{
|
||||
const bool success = writer.recordSymbolScopeLocation(
|
||||
idSymbol1,
|
||||
SourceRange({ filePath, startLine, startCol, endLine, endCol })
|
||||
{ fileId, startLine, startCol, endLine, endCol }
|
||||
);
|
||||
REQUIRE(success);
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
@@ -156,7 +157,7 @@ namespace sourcetrail
|
||||
{
|
||||
const bool success = writer.recordSymbolSignatureLocation(
|
||||
idSymbol1,
|
||||
SourceRange({ filePath, startLine, startCol, endLine, endCol })
|
||||
{ fileId, startLine, startCol, endLine, endCol }
|
||||
);
|
||||
REQUIRE(success);
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
@@ -239,6 +240,7 @@ namespace sourcetrail
|
||||
SECTION("writer records reference location")
|
||||
{
|
||||
const std::string filePath = "path/to/non_existing_file.cpp";
|
||||
const int fileId = writer.recordFile(filePath);
|
||||
const int startLine = 1;
|
||||
const int startCol = 2;
|
||||
const int endLine = 3;
|
||||
@@ -246,7 +248,7 @@ namespace sourcetrail
|
||||
|
||||
const bool success = writer.recordReferenceLocation(
|
||||
idReference1,
|
||||
SourceRange({ filePath, startLine, startCol, endLine, endCol })
|
||||
{ fileId, startLine, startCol, endLine, endCol }
|
||||
);
|
||||
REQUIRE(success);
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
@@ -375,6 +377,7 @@ namespace sourcetrail
|
||||
SECTION("writer records local symbol location")
|
||||
{
|
||||
const std::string filePath = "path/to/non_existing_file.cpp";
|
||||
const int fileId = writer.recordFile(filePath);
|
||||
const int startLine = 1;
|
||||
const int startCol = 2;
|
||||
const int endLine = 3;
|
||||
@@ -382,7 +385,7 @@ namespace sourcetrail
|
||||
|
||||
const bool success = writer.recordLocalSymbolLocation(
|
||||
idLocalSymbol1,
|
||||
SourceRange({ filePath, startLine, startCol, endLine, endCol })
|
||||
{ fileId, startLine, startCol, endLine, endCol }
|
||||
);
|
||||
REQUIRE(success);
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
@@ -426,13 +429,14 @@ namespace sourcetrail
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
|
||||
const std::string filePath = "path/to/non_existing_file.cpp";
|
||||
const int fileId = writer.recordFile(filePath);
|
||||
const int startLine = 1;
|
||||
const int startCol = 2;
|
||||
const int endLine = 3;
|
||||
const int endCol = 4;
|
||||
|
||||
const bool success1 = writer.recordCommentLocation(
|
||||
SourceRange({ filePath, startLine, startCol, endLine, endCol })
|
||||
{ fileId, startLine, startCol, endLine, endCol }
|
||||
);
|
||||
REQUIRE(success1);
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
@@ -456,7 +460,7 @@ namespace sourcetrail
|
||||
SECTION("writer does not record comment location twice")
|
||||
{
|
||||
const bool success2 = writer.recordCommentLocation(
|
||||
SourceRange({ filePath, startLine, startCol, endLine, endCol })
|
||||
{ fileId, startLine, startCol, endLine, endCol }
|
||||
);
|
||||
REQUIRE(success2);
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
@@ -487,6 +491,7 @@ namespace sourcetrail
|
||||
const std::string message = "This is a very serious test error message.";
|
||||
const bool fatal = false;
|
||||
const std::string filePath = "path/to/non_existing_file.cpp";
|
||||
const int fileId = writer.recordFile(filePath);
|
||||
const int startLine = 1;
|
||||
const int startCol = 2;
|
||||
const int endLine = 3;
|
||||
@@ -495,7 +500,7 @@ namespace sourcetrail
|
||||
const bool success1 = writer.recordError(
|
||||
message,
|
||||
fatal,
|
||||
SourceRange({ filePath, startLine, startCol, endLine, endCol })
|
||||
{ fileId, startLine, startCol, endLine, endCol }
|
||||
);
|
||||
REQUIRE(success1);
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
@@ -531,7 +536,7 @@ namespace sourcetrail
|
||||
const bool success2 = writer.recordError(
|
||||
message,
|
||||
fatal,
|
||||
SourceRange({ filePath, startLine, startCol, endLine, endCol })
|
||||
{ fileId, startLine, startCol, endLine, endCol }
|
||||
);
|
||||
REQUIRE(success2);
|
||||
REQUIRE(writer.getLastError() == "");
|
||||
|
||||
@@ -83,15 +83,15 @@ bool recordSymbolDefinitionKind(int symbolId, DefinitionKind symbolDefinitionKin
|
||||
|
||||
bool recordSymbolKind(int symbolId, SymbolKind symbolKind);
|
||||
|
||||
bool recordSymbolLocation(int symbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
|
||||
bool recordSymbolLocation(int symbolId, int fileId, int startLine, int startColumn, int endLine, int endColumn);
|
||||
|
||||
bool recordSymbolScopeLocation(int symbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
|
||||
bool recordSymbolScopeLocation(int symbolId, int fileId, int startLine, int startColumn, int endLine, int endColumn);
|
||||
|
||||
bool recordSymbolSignatureLocation(int symbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
|
||||
bool recordSymbolSignatureLocation(int symbolId, int fileId, int startLine, int startColumn, int endLine, int endColumn);
|
||||
|
||||
int recordReference(int contextSymbolId, int referencedSymbolId, ReferenceKind referenceKind);
|
||||
|
||||
bool recordReferenceLocation(int referenceId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
|
||||
bool recordReferenceLocation(int referenceId, int fileId, int startLine, int startColumn, int endLine, int endColumn);
|
||||
|
||||
int recordFile(std::string filePath);
|
||||
|
||||
@@ -99,10 +99,10 @@ bool recordFileLanguage(int fileId, std::string languageIdentifier);
|
||||
|
||||
int recordLocalSymbol(std::string name);
|
||||
|
||||
bool recordLocalSymbolLocation(int localSymbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
|
||||
bool recordLocalSymbolLocation(int localSymbolId, int fileId, int startLine, int startColumn, int endLine, int endColumn);
|
||||
|
||||
bool recordCommentLocation(std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
|
||||
bool recordCommentLocation(int fileId, int startLine, int startColumn, int endLine, int endColumn);
|
||||
|
||||
bool recordError(std::string message, bool fatal, std::string filePath, int startLine, int startColumn, int endLine, int endColumn);
|
||||
bool recordError(std::string message, bool fatal, int fileId, int startLine, int startColumn, int endLine, int endColumn);
|
||||
|
||||
#endif // SOURCETRAILDB_H
|
||||
|
||||
@@ -3,12 +3,10 @@
|
||||
#include "DefinitionKind.h"
|
||||
#include "NameHierarchy.h"
|
||||
#include "SymbolKind.h"
|
||||
#include "SourceLocation.h"
|
||||
#include "SourceRange.h"
|
||||
#include "SourcetrailDBWriter.h"
|
||||
#include "ReferenceKind.h"
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
sourcetrail::DefinitionKind convertDefinitionKind(::DefinitionKind v)
|
||||
@@ -161,19 +159,19 @@ bool recordSymbolKind(int symbolId, SymbolKind symbolKind)
|
||||
return dbWriter.recordSymbolKind(symbolId, convertSymbolKind(symbolKind));
|
||||
}
|
||||
|
||||
bool recordSymbolLocation(int symbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn)
|
||||
bool recordSymbolLocation(int symbolId, int fileId, int startLine, int startColumn, int endLine, int endColumn)
|
||||
{
|
||||
return dbWriter.recordSymbolLocation(symbolId, sourcetrail::SourceRange({ filePath, startLine, startColumn, endLine, endColumn }));
|
||||
return dbWriter.recordSymbolLocation(symbolId, { fileId, startLine, startColumn, endLine, endColumn });
|
||||
}
|
||||
|
||||
bool recordSymbolScopeLocation(int symbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn)
|
||||
bool recordSymbolScopeLocation(int symbolId, int fileId, int startLine, int startColumn, int endLine, int endColumn)
|
||||
{
|
||||
return dbWriter.recordSymbolScopeLocation(symbolId, sourcetrail::SourceRange({ filePath, startLine, startColumn, endLine, endColumn }));
|
||||
return dbWriter.recordSymbolScopeLocation(symbolId, { fileId, startLine, startColumn, endLine, endColumn });
|
||||
}
|
||||
|
||||
bool recordSymbolSignatureLocation(int symbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn)
|
||||
bool recordSymbolSignatureLocation(int symbolId, int fileId, int startLine, int startColumn, int endLine, int endColumn)
|
||||
{
|
||||
return dbWriter.recordSymbolSignatureLocation(symbolId, sourcetrail::SourceRange({ filePath, startLine, startColumn, endLine, endColumn }));
|
||||
return dbWriter.recordSymbolSignatureLocation(symbolId, { fileId, startLine, startColumn, endLine, endColumn });
|
||||
}
|
||||
|
||||
int recordReference(int contextSymbolId, int referencedSymbolId, ReferenceKind referenceKind)
|
||||
@@ -181,9 +179,9 @@ int recordReference(int contextSymbolId, int referencedSymbolId, ReferenceKind r
|
||||
return dbWriter.recordReference(contextSymbolId, referencedSymbolId, convertReferenceKind(referenceKind));
|
||||
}
|
||||
|
||||
bool recordReferenceLocation(int referenceId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn)
|
||||
bool recordReferenceLocation(int referenceId, int fileId, int startLine, int startColumn, int endLine, int endColumn)
|
||||
{
|
||||
return dbWriter.recordReferenceLocation(referenceId, sourcetrail::SourceRange({ filePath, startLine, startColumn, endLine, endColumn }));
|
||||
return dbWriter.recordReferenceLocation(referenceId, { fileId, startLine, startColumn, endLine, endColumn });
|
||||
}
|
||||
|
||||
int recordFile(std::string filePath)
|
||||
@@ -201,17 +199,17 @@ int recordLocalSymbol(std::string name)
|
||||
return dbWriter.recordLocalSymbol(name);
|
||||
}
|
||||
|
||||
bool recordLocalSymbolLocation(int localSymbolId, std::string filePath, int startLine, int startColumn, int endLine, int endColumn)
|
||||
bool recordLocalSymbolLocation(int localSymbolId, int fileId, int startLine, int startColumn, int endLine, int endColumn)
|
||||
{
|
||||
return dbWriter.recordLocalSymbolLocation(localSymbolId, sourcetrail::SourceRange({ filePath, startLine, startColumn, endLine, endColumn }));
|
||||
return dbWriter.recordLocalSymbolLocation(localSymbolId, { fileId, startLine, startColumn, endLine, endColumn });
|
||||
}
|
||||
|
||||
bool recordCommentLocation(std::string filePath, int startLine, int startColumn, int endLine, int endColumn)
|
||||
bool recordCommentLocation(int fileId, int startLine, int startColumn, int endLine, int endColumn)
|
||||
{
|
||||
return dbWriter.recordCommentLocation(sourcetrail::SourceRange({ filePath, startLine, startColumn, endLine, endColumn }));
|
||||
return dbWriter.recordCommentLocation({ fileId, startLine, startColumn, endLine, endColumn });
|
||||
}
|
||||
|
||||
bool recordError(std::string message, bool fatal, std::string filePath, int startLine, int startColumn, int endLine, int endColumn)
|
||||
bool recordError(std::string message, bool fatal, int fileId, int startLine, int startColumn, int endLine, int endColumn)
|
||||
{
|
||||
return dbWriter.recordError(message, fatal, sourcetrail::SourceRange({ filePath, startLine, startColumn, endLine, endColumn }));
|
||||
return dbWriter.recordError(message, fatal, { fileId, startLine, startColumn, endLine, endColumn });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user