-
-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace mocks/stubs in tests with LSP #21
Changes from 6 commits
370aab9
772a1e9
d0a43a4
0bc7026
cc43cea
acf765a
ba2e86e
22ca47c
4d49e7e
929ef9f
70c76a3
3ed23d6
4a238c2
05d8c00
166ccb3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,21 +66,15 @@ function isValidUnistPoint(point) { | |
*/ | ||
function unistLocationToLspRange(position) { | ||
if (position) { | ||
if (isValidUnistPoint(position.start)) { | ||
if (isValidUnistPoint(position.end)) { | ||
return Range.create( | ||
unistPointToLspPosition(position.start), | ||
unistPointToLspPosition(position.end) | ||
) | ||
} | ||
|
||
const start = unistPointToLspPosition(position.start) | ||
return Range.create(start, start) | ||
} | ||
|
||
if (isValidUnistPoint(position.end)) { | ||
const end = unistPointToLspPosition(position.end) | ||
return Range.create(end, end) | ||
const end = isValidUnistPoint(position.end) | ||
? unistPointToLspPosition(position.end) | ||
: undefined | ||
const start = isValidUnistPoint(position.start) | ||
? unistPointToLspPosition(position.start) | ||
: end | ||
|
||
if (start) { | ||
return Range.create(start, end || start) | ||
} | ||
} | ||
|
||
|
@@ -96,7 +90,7 @@ function unistLocationToLspRange(position) { | |
function vfileMessageToDiagnostic(message) { | ||
const diagnostic = Diagnostic.create( | ||
unistLocationToLspRange(message.position), | ||
message.reason, | ||
String(message.stack || message.reason), | ||
wooorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
message.fatal === true | ||
? DiagnosticSeverity.Error | ||
: message.fatal === false | ||
|
@@ -175,7 +169,7 @@ export function configureUnifiedLanguageServer( | |
streamError: new PassThrough(), | ||
streamOut: new PassThrough() | ||
}, | ||
(error, code, context) => { | ||
(error, _, context) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer using a proper name for variables, even if they are unused. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Main reason for me is that TS in my editor is info’ing about it being unused otherwise. I’d be 🤷♂️ otherwise |
||
// An error never occur and can’t be reproduced. Thus us ab internal | ||
// error in unified-engine. If a plugin throws, it’s reported as a | ||
// vfile message. | ||
|
@@ -185,7 +179,7 @@ export function configureUnifiedLanguageServer( | |
} else { | ||
resolve((context && context.files) || []) | ||
} | ||
/* c8 ignore end */ | ||
/* c8 ignore stop */ | ||
wooorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
) | ||
}) | ||
|
@@ -227,8 +221,12 @@ export function configureUnifiedLanguageServer( | |
} | ||
})) | ||
|
||
connection.onDocumentFormatting(async ({textDocument: {uri}}) => { | ||
connection.onDocumentFormatting(async (event) => { | ||
const {uri} = event.textDocument | ||
const document = documents.get(uri) | ||
wooorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// `vscode-languageserver` crashes for commands to format unopen documents. | ||
/* c8 ignore next 3 */ | ||
if (!document) { | ||
return | ||
} | ||
|
@@ -243,13 +241,16 @@ export function configureUnifiedLanguageServer( | |
const start = Position.create(0, 0) | ||
const end = document.positionAt(text.length) | ||
|
||
// V8 coverage bug on Dubnium (Node 12). | ||
wooorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/* c8 ignore next 2 */ | ||
return [TextEdit.replace(Range.create(start, end), result)] | ||
}) | ||
|
||
documents.onDidChangeContent((event) => { | ||
checkDocuments(event.document) | ||
}) | ||
|
||
// Send empty diagnostics for closed files. | ||
documents.onDidClose((event) => { | ||
const {uri, version} = event.document | ||
connection.sendDiagnostics({ | ||
|
@@ -259,15 +260,20 @@ export function configureUnifiedLanguageServer( | |
}) | ||
}) | ||
|
||
// Check everything again if something changes. | ||
wooorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
connection.onDidChangeWatchedFiles(() => { | ||
checkDocuments(...documents.all()) | ||
}) | ||
|
||
connection.onCodeAction((event) => { | ||
const {uri} = event.textDocument | ||
/** @type {CodeAction[]} */ | ||
const codeActions = [] | ||
|
||
const document = documents.get(event.textDocument.uri) | ||
const document = documents.get(uri) | ||
wooorm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// `vscode-languageserver` crashes for commands to act on unopen documents. | ||
/* c8 ignore next 3 */ | ||
if (!document) { | ||
return | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
easier to reach coverage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn’t catch the situation if
end
is a valid unist point, butstart
isn’t. I recall running into this in a real rule while testing manually, but I don’t remember which one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should work: see L72’s else case on L74!
(it’s a rather weird case you ran into btw, I don’t remember seeing something like that. Still: I’m all for very “defensive” / “safe” code for this 👍)