Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
B Language Extension
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
general
stups
B Language Extension
Commits
de7da51a
Commit
de7da51a
authored
4 years ago
by
SeeBasTStick
Browse files
Options
Downloads
Patches
Plain Diff
refactored ndjson format and implemented correct behavior when files get corrected
parent
c88f1614
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
server/src/errorHandler.ts
+51
-34
51 additions, 34 deletions
server/src/errorHandler.ts
server/src/server.ts
+44
-43
44 additions, 43 deletions
server/src/server.ts
with
95 additions
and
77 deletions
server/src/errorHandler.ts
+
51
−
34
View file @
de7da51a
...
...
@@ -5,12 +5,9 @@ import * as readline from 'readline'
/**
* Reads the error file, casts the errors to a readable form, sorts them by origin
* @param errorPath the path to the file where the ndjson errors are stored
*/
export
async
function
readErrors
(
errorPath
:
string
):
Promise
<
Map
<
string
,
Set
<
NDJSON
>>>
{
let
result
:
Map
<
string
,
Set
<
NDJSON
>>
=
new
Map
()
export
async
function
readErrors
(
errorPath
:
string
)
:
Promise
<
Array
<
string
>>
{
let
lines
:
Array
<
string
>
=
new
Array
()
var
stream
=
fs
.
createReadStream
(
errorPath
)
...
...
@@ -19,9 +16,23 @@ export async function readErrors(errorPath: string): Promise<Map<string, Set<NDJ
crlfDelay
:
Infinity
});
let
i
:
number
=
1
for
await
(
const
line
of
rl
){
lines
.
push
(
line
)
}
return
lines
}
/**
* Reads the error file, casts the errors to a readable form, sorts them by origin
* @param errorLines an array containing all errors
*/
export
function
buildErrors
(
errorLines
:
Array
<
string
>
):
Map
<
string
,
Set
<
NDJSON
>>
{
let
result
:
Map
<
string
,
Set
<
NDJSON
>>
=
new
Map
()
let
i
:
number
=
2
for
(
const
line
of
errorLines
)
{
let
obj
:
NDJSON
...
...
@@ -31,7 +42,8 @@ export async function readErrors(errorPath: string): Promise<Map<string, Set<NDJ
throw
Error
(
e
.
message
+
"
at line
"
+
line
)
}
i
++
let
path
:
string
=
obj
.
details
.
file
let
path
=
obj
.
file
if
(
!
result
.
has
(
path
)){
...
...
@@ -50,10 +62,10 @@ export async function readErrors(errorPath: string): Promise<Map<string, Set<NDJ
*/
export
function
matchErrors
(
infos
:
Set
<
NDJSON
>
,
file
?:
TextDocument
|
undefined
):
Array
<
Diagnostic
>
{
let
result
:
Array
<
Diagnostic
>
=
new
Array
()
console
.
log
(
"
infos
"
+
infos
)
for
(
var
info
of
infos
)
{
console
.
log
(
"
type
"
+
info
.
type
)
let
serveity
:
DiagnosticSeverity
=
DiagnosticSeverity
.
Error
if
(
info
.
type
==
"
error
"
)
{
...
...
@@ -68,37 +80,37 @@ export function matchErrors(infos: Set<NDJSON>, file?: TextDocument | undefined)
serveity
=
DiagnosticSeverity
.
Information
}
let
content
:
JBody
=
info
.
details
// Managing case we get conent with no error massage
if
(
content
.
start
.
line
==
-
1
&&
content
.
start
.
col
==
-
1
&&
content
.
end
.
line
==
-
1
&&
content
.
end
.
col
==
-
1
)
{
if
(
info
.
start
.
line
==
-
1
&&
info
.
start
.
col
==
-
1
&&
info
.
end
.
line
==
-
1
&&
info
.
end
.
col
==
-
1
)
{
if
(
file
!=
undefined
)
{
//Due to server architecture we only have the most actual document
let
targetLine
=
getFirstOccurence
(
file
).
line
content
.
start
=
{
line
:
targetLine
,
col
:
0
}
content
.
end
=
{
line
:
targetLine
,
col
:
Number
.
MAX_VALUE
}
info
.
start
=
{
line
:
targetLine
,
col
:
0
}
info
.
end
=
{
line
:
targetLine
,
col
:
Number
.
MAX_VALUE
}
}
else
{
//Fallback if an error occurs on differnt document
content
.
start
=
{
line
:
1
,
col
:
0
}
content
.
end
=
{
line
:
1
,
col
:
Number
.
MAX_VALUE
}
info
.
start
=
{
line
:
1
,
col
:
0
}
info
.
end
=
{
line
:
1
,
col
:
Number
.
MAX_VALUE
}
}
}
let
diagnostic
=
{
let
diagnostic
:
Diagnostic
=
{
severity
:
serveity
,
range
:
{
start
:
{
character
:
content
.
start
.
col
,
line
:
content
.
start
.
line
-
1
character
:
info
.
start
.
col
,
line
:
info
.
start
.
line
-
1
},
end
:
{
character
:
content
.
end
.
col
,
line
:
content
.
end
.
line
-
1
character
:
info
.
end
.
col
,
line
:
info
.
end
.
line
-
1
}
},
message
:
content
.
message
,
source
:
content
.
file
,
message
:
info
.
message
,
source
:
info
.
file
,
code
:
"
probcli v.
"
+
info
.
prob_version
};
...
...
@@ -113,22 +125,27 @@ export function matchErrors(infos: Set<NDJSON>, file?: TextDocument | undefined)
////////////// Representation of the NDJSON File
export
interface
NDJSON
{
type
:
string
details
:
JBody
message
:
string
reason
:
string
file
:
string
start
:
StartOrEnd
end
:
StartOrEnd
prob_version
:
string
// main_file : string
// dependencies : Array<string>
}
export
interface
JBody
{
message
:
string
;
type
:
string
;
file
:
string
;
start
:
StartOrEnd
;
end
:
StartOrEnd
;
}
export
interface
StartOrEnd
{
line
:
number
;
col
:
number
;
}
///////////////////
...
...
This diff is collapsed.
Click to expand it.
server/src/server.ts
+
44
−
43
View file @
de7da51a
...
...
@@ -19,7 +19,7 @@ import {
import
{
URI
}
from
'
vscode-uri
'
;
import
*
as
fs
from
'
fs
'
;
import
{
NDJSON
,
readErrors
,
matchErrors
}
from
'
./errorHandler
'
;
import
{
NDJSON
,
readErrors
,
matchErrors
,
buildErrors
}
from
'
./errorHandler
'
;
import
*
as
wordComplition
from
'
./wordCompletion
'
import
*
as
path
from
'
path
'
;
import
*
as
URL
from
'
url
'
...
...
@@ -167,7 +167,7 @@ documents.onDidChangeContent(change => {
});
let
issueTracker
:
Map
<
string
,
Array
<
string
>>
=
new
Map
()
async
function
validateTextDocument
(
textDocument
:
TextDocument
):
Promise
<
void
>
{
...
...
@@ -186,55 +186,56 @@ async function validateTextDocument(textDocument: TextDocument): Promise<void> {
}
fs
.
writeFile
(
errorPath
,
""
,
()
=>
{
})
//Insure a clean error file
//fs.writeFileSync(errorPath,"",{encoding:'utf8',flag:'w'})
if
(
!
issueTracker
.
has
(
textDocument
.
uri
)){
//ensure that position is always initalised
issueTracker
.
set
(
textDocument
.
uri
,
new
Array
())
}
fs
.
writeFileSync
(
errorPath
,
""
,{
encoding
:
'
utf8
'
,
flag
:
'
w
'
})
let
command
:
string
=
getCommand
(
URI
.
parse
(
textDocument
.
uri
).
path
,
errorPath
,
settings
)
// console.log(command)
if
(
correctPath
(
settings
.
probHome
))
{
exec
(
command
,
(
err
:
string
,
stdout
:
string
,
stderr
:
string
)
=>
{
let
errorMap
:
Promise
<
Map
<
string
,
Set
<
NDJSON
>>>
=
readErrors
(
errorPath
)
errorMap
.
then
(
function
(
result
:
Map
<
string
,
Set
<
NDJSON
>>
)
{
let
errorLines
:
Promise
<
Array
<
string
>>
=
readErrors
(
errorPath
)
let
diagnostics
:
Array
<
Diagnostic
>
=
new
Array
()
if
(
result
.
size
!=
0
)
errorLines
.
then
(
function
(
result
:
Array
<
string
>
)
{
let
allFilesAndCorrespondingErrors
:
Map
<
string
,
Set
<
NDJSON
>>
=
buildErrors
(
result
);
let
filesWithProblemms
:
Array
<
string
>
=
Array
.
from
(
allFilesAndCorrespondingErrors
.
keys
())
for
(
let
dependency
of
allFilesAndCorrespondingErrors
.
keys
())
{
let
mainFileWritten
:
boolean
=
false
;
for
(
let
entry
of
result
)
{
if
(
entry
[
0
]
==
textDocument
.
uri
)
{
diagnostics
=
matchErrors
(
entry
[
1
],
textDocument
)
console
.
log
(
dependency
)
console
.
log
(
documentPath
.
dir
+
documentPath
.
name
+
documentPath
.
ext
)
if
(
dependency
==
(
documentPath
.
dir
+
documentPath
.
name
+
documentPath
.
ext
)){
console
.
log
(
"
is:main
"
)
let
errors
:
Set
<
NDJSON
>
=
allFilesAndCorrespondingErrors
.
get
(
dependency
)
!!
console
.
log
(
"
errors
"
+
errors
)
let
diagnostics
=
matchErrors
(
errors
,
textDocument
)
connection
.
sendDiagnostics
({
uri
:
dependency
,
diagnostics
});
}
else
{
diagnostics
=
matchErrors
(
entry
[
1
])
}
connection
.
sendDiagnostics
({
uri
:
entry
[
0
],
diagnostics
});
/**
* TL;DR we need to cast here to clean the main file
*
* This is a little bit of a mess here: Problem the paths in the _error.json a system relevant
* and system centered e.g. /home/sebastian...
*
* The URI from the textdocument is domain centered e.g. file///home/sebastian in order to deal
* with remote files like serverXYZ///home/michael
*
* However the extension.ts can deal with system centric paths and uris, but we need a comparision
* so we have to cast here...
*/
if
(
URI
.
parse
(
entry
[
0
]).
toString
()
==
textDocument
.
uri
){
mainFileWritten
=
true
console
.
log
(
"
is:dep
"
)
let
errors
:
Set
<
NDJSON
>
=
allFilesAndCorrespondingErrors
.
get
(
dependency
)
!!
let
diagnostics
=
matchErrors
(
errors
)
console
.
log
(
"
errors
"
+
errors
)
connection
.
sendDiagnostics
({
uri
:
dependency
,
diagnostics
});
}
}
if
(
mainFileWritten
==
false
){
// The main file has no errors, we need to reset it...
diagnostics
=
new
Array
()
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
});
let
filesToReset
:
Array
<
string
>
=
issueTracker
.
get
(
textDocument
.
uri
)
!
.
filter
(
function
(
obj
)
{
return
filesWithProblemms
.
indexOf
(
obj
)
==
-
1
;
});
for
(
let
dependency
of
filesToReset
)
{
console
.
log
(
"
reset:errrors
"
)
let
diagnostics
:
Array
<
Diagnostic
>
=
new
Array
()
connection
.
sendDiagnostics
({
uri
:
dependency
,
diagnostics
});
}
}
else
{
connection
.
sendDiagnostics
({
uri
:
textDocument
.
uri
,
diagnostics
});
}
issueTracker
.
set
(
textDocument
.
uri
,
Array
.
from
(
allFilesAndCorrespondingErrors
.
keys
()))
},
function
(
err
)
{
connection
.
sendNotification
(
"
parse_error_prob
"
,
"
there are things wrong with the parse results
"
+
err
)
});
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment