aboutsummaryrefslogtreecommitdiffstats
path: root/src/shared/lsp/link.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/shared/lsp/link.cpp')
-rw-r--r--src/shared/lsp/link.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/shared/lsp/link.cpp b/src/shared/lsp/link.cpp
new file mode 100644
index 000000000..e25b828d7
--- /dev/null
+++ b/src/shared/lsp/link.cpp
@@ -0,0 +1,35 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
+
+#include "link.h"
+
+#include "textutils.h"
+
+namespace lsp::Utils {
+
+/*!
+ Returns the Link to \a filePath.
+ If \a canContainLineNumber is true the line number, and column number components
+ are extracted from the \a filePath's \c path() and the found \a postfix is set.
+
+ The following patterns are supported: \c {filepath.txt:19},
+ \c{filepath.txt:19:12}, \c {filepath.txt+19},
+ \c {filepath.txt+19+12}, and \c {filepath.txt(19)}.
+*/
+
+Link Link::fromString(const QString &filePathWithNumbers, bool canContainLineNumber)
+{
+ Link link;
+ if (!canContainLineNumber) {
+ link.targetFilePath = FilePath::fromUserInput(filePathWithNumbers);
+ } else {
+ int postfixPos = -1;
+ const Text::Position pos = Text::Position::fromFileName(filePathWithNumbers, postfixPos);
+ link.targetFilePath = FilePath::fromUserInput(filePathWithNumbers.left(postfixPos));
+ link.targetLine = pos.line;
+ link.targetColumn = pos.column;
+ }
+ return link;
+}
+
+} // namespace lsp::Utils