Merge pull request #10 from alexnask/master
Renamed documentContext to documentPositionContext, added multiline string literal support
This commit is contained in:
commit
cc38b0f9ad
10
src/main.zig
10
src/main.zig
@ -311,7 +311,7 @@ const PositionContext = enum {
|
|||||||
empty
|
empty
|
||||||
};
|
};
|
||||||
|
|
||||||
fn documentContext(doc: types.TextDocument, pos_index: usize) PositionContext {
|
fn documentPositionContext(doc: types.TextDocument, pos_index: usize) PositionContext {
|
||||||
// First extract the whole current line up to the cursor.
|
// First extract the whole current line up to the cursor.
|
||||||
var curr_position = pos_index;
|
var curr_position = pos_index;
|
||||||
while (curr_position > 0) : (curr_position -= 1) {
|
while (curr_position > 0) : (curr_position -= 1) {
|
||||||
@ -325,9 +325,11 @@ fn documentContext(doc: types.TextDocument, pos_index: usize) PositionContext {
|
|||||||
if (curr_position >= line.len) return .empty;
|
if (curr_position >= line.len) return .empty;
|
||||||
line = line[curr_position .. ];
|
line = line[curr_position .. ];
|
||||||
|
|
||||||
// Quick exit for whole-comment lines.
|
// Quick exit for comment lines and multi line string literals.
|
||||||
if (line.len > 2 and line[0] == '/' and line[1] == '/')
|
if (line.len >= 2 and line[0] == '/' and line[1] == '/')
|
||||||
return .comment;
|
return .comment;
|
||||||
|
if (line.len >= 2 and line[0] == '\\' and line[1] == '\\')
|
||||||
|
return .string_literal;
|
||||||
|
|
||||||
// TODO: This does not detect if we are in a string literal over multiple lines.
|
// TODO: This does not detect if we are in a string literal over multiple lines.
|
||||||
// Find out what context we are in.
|
// Find out what context we are in.
|
||||||
@ -516,7 +518,7 @@ fn processJsonRpc(parser: *std.json.Parser, json: []const u8) !void {
|
|||||||
};
|
};
|
||||||
if (pos.character >= 0) {
|
if (pos.character >= 0) {
|
||||||
const pos_index = try document.positionToIndex(pos);
|
const pos_index = try document.positionToIndex(pos);
|
||||||
const pos_context = documentContext(document.*, pos_index);
|
const pos_context = documentPositionContext(document.*, pos_index);
|
||||||
|
|
||||||
if (pos_context == .builtin) {
|
if (pos_context == .builtin) {
|
||||||
try send(types.Response{
|
try send(types.Response{
|
||||||
|
Loading…
Reference in New Issue
Block a user