summaryrefslogtreecommitdiff
path: root/source/slang/slang-workspace-version.cpp
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2022-06-07 14:57:35 -0700
committerGitHub <noreply@github.com>2022-06-07 14:57:35 -0700
commit01d0154ae90f5c587321d39b8fd8f82e2764f360 (patch)
tree3f441db0781e9fd4ebcccf4cbf7d743f4910c72d /source/slang/slang-workspace-version.cpp
parent0c64995ea28febcc7d38e1519da8d93391ce2e7d (diff)
Code review fixes for language server. (#2265)
* Code review fixes for language server. * Fix clang error. * update solution file Co-authored-by: Yong He <yhe@nvidia.com>
Diffstat (limited to 'source/slang/slang-workspace-version.cpp')
-rw-r--r--source/slang/slang-workspace-version.cpp57
1 files changed, 16 insertions, 41 deletions
diff --git a/source/slang/slang-workspace-version.cpp b/source/slang/slang-workspace-version.cpp
index 7fef7430e..29404c2d0 100644
--- a/source/slang/slang-workspace-version.cpp
+++ b/source/slang/slang-workspace-version.cpp
@@ -1,6 +1,7 @@
#include "slang-workspace-version.h"
#include "../core/slang-io.h"
#include "../core/slang-file-system.h"
+#include "../core/slang-char-util.h"
#include "../compiler-core/slang-lexer.h"
namespace Slang
@@ -73,34 +74,10 @@ void Workspace::init(List<URI> rootDirURI, slang::IGlobalSession* globalSession)
void Workspace::invalidate() { currentVersion = nullptr; }
-int parseInt(UnownedStringSlice text, Index& pos)
-{
- int result = 0;
- while (text[pos] == ' ' && pos < text.getLength())
- {
- pos++;
- continue;
- }
- while (pos < text.getLength())
- {
- if (text[pos] >= '0' && text[pos] <= '9')
- {
- result *= 10;
- result += text[pos] - '0';
- pos++;
- }
- else
- {
- break;
- }
- }
- return result;
-}
-
void parseDiagnostics(Dictionary<String, DocumentDiagnostics>& diagnostics, String compilerOutput)
{
List<UnownedStringSlice> lines;
- StringUtil::split(compilerOutput.getUnownedSlice(), '\n', lines);
+ StringUtil::calcLines(compilerOutput.getUnownedSlice(), lines);
for (Index lineIndex = 0; lineIndex < lines.getCount(); lineIndex++)
{
auto line = lines[lineIndex];
@@ -116,12 +93,12 @@ void parseDiagnostics(Dictionary<String, DocumentDiagnostics>& diagnostics, Stri
LanguageServerProtocol::Diagnostic diagnostic;
Index pos = lparentIndex + 1;
- int lineLoc = parseInt(line, pos);
+ int lineLoc = StringUtil::parseInt(line, pos);
if (lineLoc == 0)
lineLoc = 1;
diagnostic.range.end.line = diagnostic.range.start.line = lineLoc - 1;
pos++;
- int colLoc = parseInt(line, pos);
+ int colLoc = StringUtil::parseInt(line, pos);
if (colLoc == 0)
colLoc = 1;
diagnostic.range.end.character = diagnostic.range.start.character = colLoc - 1;
@@ -148,13 +125,13 @@ void parseDiagnostics(Dictionary<String, DocumentDiagnostics>& diagnostics, Stri
continue;
}
pos = line.indexOf(' ');
- diagnostic.code = parseInt(line, pos);
+ diagnostic.code = StringUtil::parseInt(line, pos);
diagnostic.message = line.subString(colonIndex + 2, line.getLength());
if (lineIndex + 1 < lines.getCount() && lines[lineIndex].startsWith("^+"))
{
lineIndex++;
pos = 2;
- auto tokenLength = parseInt(lines[lineIndex], pos);
+ auto tokenLength = StringUtil::parseInt(lines[lineIndex], pos);
diagnostic.range.end.character += tokenLength;
}
diagnosticList.messages.Add(diagnostic);
@@ -215,17 +192,6 @@ void* Workspace::getInterface(const Guid& uuid)
return nullptr;
}
-Int convertHexDigit(char c)
-{
- if (c >= '0' && c <= '9')
- return c - '0';
- if (c >= 'A' && c <= 'F')
- return c - 'A' + 10;
- if (c >= 'a' && c <= 'f')
- return c - 'a' + 10;
- return 0;
-}
-
String URI::getPath() const
{
Index startIndex = uri.indexOf("://");
@@ -244,7 +210,8 @@ String URI::getPath() const
auto ch = uri[i];
if (ch == '%')
{
- Int charVal = convertHexDigit(uri[i + 1]) * 16 + convertHexDigit(uri[i + 2]);
+ Int charVal = CharUtil::getHexDigitValue(uri[i + 1]) * 16 +
+ CharUtil::getHexDigitValue(uri[i + 2]);
sb.appendChar((char)charVal);
i += 3;
}
@@ -257,6 +224,14 @@ String URI::getPath() const
return sb.ProduceString();
}
+StringSlice URI::getProtocol() const
+{
+ Index separatorIndex = uri.indexOf("://");
+ if (separatorIndex != -1)
+ return uri.subString(0, separatorIndex);
+ return StringSlice();
+}
+
bool URI::isSafeURIChar(char ch)
{
return (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') ||