Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions uni/ulsp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ UFLAGS=-s -u
prog=ulsp

SRC=launch-lsp.icn file_handler.icn database.icn server.icn completion.icn signature.icn hover.icn \
definition.icn jsonrpc.icn logger.icn lsif.icn
definition.icn jsonrpc.icn logger.icn lsif.icn symbols.icn folding.icn
OBJ=launch-lsp.u file_handler.u database.u server.u completion.u signature.u hover.u definition.u \
jsonrpc.u logger.u lsif.u
jsonrpc.u logger.u lsif.u symbols.u folding.u

export IPATH=$(UNI)/unidoc

Expand All @@ -22,10 +22,12 @@ $(prog): $(OBJ)
jsonrpc-test: jsonrpc-test.u jsonrpc.u
$(UC) -o jsonrpc-test jsonrpc-test.u jsonrpc.u

launch-lsp.u: launch-lsp.icn file_handler.u database.u server.u completion.u signature.u hover.u definition.u
launch-lsp.u:launch-lsp.icn file_handler.u database.u server.u completion.u signature.u hover.u \
definition.u symbols.u folding.u

server.u: server.icn database.u completion.u file_handler.u signature.u hover.u definition.u jsonrpc.u logger.u
hover.u: hover.icn signature.u
server.u:server.icn database.u completion.u file_handler.u signature.u hover.u definition.u jsonrpc.u \
logger.u symbols.u folding.u
hover.u:hover.icn signature.u
definition.u: definition.icn hover.u

zip:
Expand Down
2 changes: 0 additions & 2 deletions uni/ulsp/database.icn
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,6 @@ class LSPDB(
file_in_pack.getName() ? {
file_without_ext := tab(upto("."))
}


file_table[file_without_ext] := table()

/file_table[file_without_ext]["imports"] := []
Expand Down
148 changes: 142 additions & 6 deletions uni/ulsp/file_handler.icn
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# -------------------------------------------------------------------------
# ---------------------- FileHandler Class ----------------------------------
# ---------------------- FileHandler Class --------------------------------
# -------------------------------------------------------------------------
#
# Description:
Expand Down Expand Up @@ -50,7 +50,8 @@ class FileHandler(
package_classes,
m_uni_file,
temp_idoc,
context
context,
internal_positions
)

method updateFileHandler()
Expand All @@ -67,6 +68,7 @@ class FileHandler(
setPackageClasses()
setObjects()
setVariables()
setInternalPositions()
end

method setFile()
Expand Down Expand Up @@ -247,7 +249,7 @@ class FileHandler(
end

# -------------------------------------------------------------------------------------------------
# ---------------- Package Procedures (get, set, update) -----------------------------------------
# ---------------- Package Procedures (get, set, update) ------------------------------------------
# -------------------------------------------------------------------------------------------------

method setPackageProcedures()
Expand Down Expand Up @@ -377,7 +379,7 @@ class FileHandler(
end

# -------------------------------------------------------------------------------------------------
# ---------------- Package Classes (get, set, update) --------------------------------------------
# ---------------- Package Classes (get, set, update) ---------------------------------------------
# -------------------------------------------------------------------------------------------------

method setPackageClasses()
Expand Down Expand Up @@ -427,7 +429,7 @@ class FileHandler(
end

# -------------------------------------------------------------------------------------------------
# ---------------- Variables (get, set, update) -----------------------------------------------------
# ---------------- Variables (get, set, update) ---------------------------------------------------
# -------------------------------------------------------------------------------------------------

method setVariables()
Expand Down Expand Up @@ -486,6 +488,140 @@ class FileHandler(
return global_variables
end

# -------------------------------------------------------------------------------------------------
# ---------------- Ranges (get, set) --------------------------------------------------------------
# -------------------------------------------------------------------------------------------------

method setInternalPositions()
local lineNum, _line, procedureName, startPos, endPos, className, methodName, variableName,
open_blocks, ending, currentClass

internal_positions := [
"classes" : table();
"procedures" : table();
"methods" : table();
"variables" : table();
"initially" : table()
]
open_blocks := []

lineNum := 1
while _line := temp_idoc.getUniFileLine(uri, lineNum) do {
# Check for procedures
every procedureName := key(internal_procedures) do {
if ReMatch("procedure\\s+" || procedureName || "\\s*\\(", _line) then {
startPos := find(procedureName, _line)
endPos := startPos + *procedureName - 1
push(open_blocks, ["procedures", procedureName])
internal_positions["procedures"][procedureName] := [
"type" : "procedure";
"range" : [
"start" : [lineNum-1, 0];
"end" : [lineNum-1, 0]
];
"selectionRange" : [
"start" : [lineNum-1, startPos];
"end" : [lineNum-1, endPos]
]
]
}
}

# Check for classes
every className := key(internal_classes) do {
if ReMatch("class\\s+" || className || "\\s*\\(", _line) then {
currentClass := className
startPos := find(className, _line)
endPos := startPos + *className - 1
push(open_blocks, ["classes", className])
internal_positions["classes"][className] := [
"type" : "class";
"range" : [
"start" : [lineNum-1, 0];
"end" : [lineNum-1, 0]
];
"selectionRange" : [
"start" : [lineNum-1, startPos];
"end" : [lineNum-1, endPos]
]
]
}

# Check for methods
every methodName := key(internal_classes[className]["methods"]) do {
if ReMatch(".*method\\s+" || methodName || "\\s*\\(", _line) then {
startPos := find(methodName, _line)
endPos := startPos + *methodName - 1
push(open_blocks, ["methods", methodName])
internal_positions["methods"][methodName] := [
"type" : "method";
"range" : [
"start" : [lineNum-1, 0];
"end" : [lineNum-1, 0]
];
"selectionRange" : [
"start" : [lineNum-1, startPos];
"end" : [lineNum-1, endPos]
]
]
}
}
}

# Check for "initially" sections
if ReMatch("^\\s*initially\\s*(\\(.*\\))?$", _line) then {
startPos := find("initially", _line)
endPos := startPos + 9
push(open_blocks, ["initially", currentClass])
internal_positions["initially"][currentClass] := [
"type" : "method";
"range" : [
"start" : [lineNum-1, 0];
"end" : [lineNum-1, 0]
];
"selectionRange" : [
"start" : [lineNum-1, startPos];
"end" : [lineNum-1, endPos]
]
]
}

# Check for keyword "end"
if ReMatch("^\\s*end\\s*$", _line) then {
if *open_blocks > 0 then {
ending := pop(open_blocks)
if ending[1] == "initially" then {
internal_positions[ending[1]][ending[2]]["range"]["end"] := [lineNum-2, *temp_idoc.getUniFileLine(uri, lineNum-1)]
ending := pop(open_blocks)
internal_positions[ending[1]][ending[2]]["range"]["end"] := [lineNum-1, *_line]
} else {
internal_positions[ending[1]][ending[2]]["range"]["end"] := [lineNum-1, *_line]
}
}
}

# Check for variables
every variableName := key(variables) do {
if ReMatch("^\\s*" || variableName || "\\s*\\:=", _line) then {
startPos := find(variableName, _line)
endPos := startPos + *variableName - 1
internal_positions["variables"][variableName] := table(
"type", "variable",
"selectionRange", table(
"start", [lineNum-1, startPos-1],
"end", [lineNum-1, endPos]
)
)
}
}
lineNum +:= 1
}
end

method getInternalPositions()
return internal_positions
end

# -------------------------------------------------------------------------------------------------
# ---------------- Database accessors -------------------------------------------------------------
# -------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -604,7 +740,7 @@ class Context(uniAll, uri, line, lineNum, charNum, objectName, methodName, conte
line := uniAll.getUniFileLine(uri, lineNum)
end

# Retrive object name #
# Retrieve object name #
method getObjectName()
local temp, c, name
line ? {
Expand Down
119 changes: 119 additions & 0 deletions uni/ulsp/folding.icn
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
package ulsp

link regexp
link ximage

# Processes all folding ranges in a document and constructs a result to return to the client.
class FoldingRangeHandler(filehandler)

# Sets the class variables for the FoldingRangeHandler.
# Params: new_filehandler - The filehandler object created from the parameters of the
# request sent by the client.
method setVariables(new_filehandler)
filehandler := new_filehandler
end

# Searches through the provided filehandler for all internal positions of symbols and
# constructs a result to send back to the client for all folding ranges.
method run()
local results_list, tokenKind, tokenName, entry, startLine, endLine, result

results_list := []

every tokenKind := key(filehandler.internal_positions) do {
every tokenName := key(filehandler.internal_positions[tokenKind]) do {
entry := filehandler.internal_positions[tokenKind][tokenName]

if member(entry, "range") then {
startLine := entry["range"]["start"][1]
endLine := entry["range"]["end"][1] - 1

if tokenKind == "initially" then endLine+:=1
if startLine < endLine then {
put(results_list, table(
"startLine", startLine,
"endLine", endLine
))
}
}
}
}

return results_list |||:= findFoldingRanges()
end

# Parse through the filehandler's temp_idoc parser to find all regions that are
# large blocks of comments, large blocks of imports or links, and open sections
# between curly brackets.
# <i>This is intended for internal use only!</i>
method findFoldingRanges()
local lineNum, _line, commentBlock, commentLine, results_list, open_blocks, startLine, character, ch,
single_quote, double_quote, importBlock, importLine

lineNum := 1
commentBlock := 0
importBlock := 0
results_list := []
open_blocks := []
while _line := filehandler.temp_idoc.getUniFileLine(filehandler.uri, lineNum) do {
if ReMatch("^\\s*#.*$", _line) then {
commentBlock +:= 1
if commentBlock = 1 then commentLine := lineNum
} else {
if commentBlock > 1 then {
put(results_list, table(
"startLine", commentLine-1,
"endLine", lineNum-2
))
}
commentBlock := 0
if ReMatch("^(link|import)\\s+.*", _line) then {
importBlock +:= 1
if importBlock = 1 then importLine := lineNum
} else {
if importBlock > 1 then {
put(results_list, table(
"startLine", importLine-1,
"endLine", lineNum-2
))
}
importBlock := 0
}
if *open_blocks > 0 & character := ReMatch(".*\\}", _line) then {
_line ? {
single_quote := 0
double_quote := 0
while (&pos < character) do {
ch := move(1) | break
if (ch == "\'" & (_line[&pos-2] ~== "\\")) then single_quote +:= 1
if (ch == "\"" & (_line[&pos-2] ~== "\\")) then double_quote +:= 1
}
if (single_quote % 2) = 0 && (double_quote % 2) = 0 then {
startLine := pop(open_blocks)
put(results_list, table(
"startLine", startLine-1,
"endLine", lineNum-2
))
}
}
}
if character := ReMatch(".*\\{", _line) then {
_line ? {
single_quote := 0
double_quote := 0
while (&pos < character) do {
ch := move(1) | break
if (ch == "\'" & (_line[&pos-2] ~== "\\")) then single_quote +:= 1
if (ch == "\"" & (_line[&pos-2] ~== "\\")) then double_quote +:= 1
}
if (single_quote % 2) = 0 && (double_quote % 2) = 0 then {
push(open_blocks, lineNum)
}
}
}
}
lineNum +:= 1
}
return results_list
end
end
2 changes: 1 addition & 1 deletion uni/ulsp/lsif.icn
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ class LSIFIndexer(
write(outFile, tojson(lsif_table))
end

# Creates an contains edge that links all of the ranges in a document to that document.
# Creates a contains edge that links all of the ranges in a document to that document,
# or all the documents to a project.
# Params: outID - The ID that this edge is pointing out from, either the document or project ID.
# contains_table - The table with ID's of all ranges in a document or documents in a project.
Expand Down
Loading