-
Notifications
You must be signed in to change notification settings - Fork 98
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
Update test callable discovery to work within the language service #2095
base: main
Are you sure you want to change the base?
Conversation
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.
Not done looking at all the files, posting all my comments for today.
let location = Location { | ||
source: source.name.clone(), | ||
range: Range::from_span(Encoding::Utf8, &source.contents, &(span - source.offset)), | ||
}; |
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.
JavaScript is utf-16 😭 and that's why we can't make assumptions in the native crates about encoding (utf-8 for Rust/Python, utf-16 for JavaScript). This function should take position_encoding
as a parameter.
But also... This is just dead code now. Do we still want to expose ICompiler.getTestCallables()
? I think we should just remove it since it's not used in the new approach.
serializable_type! { | ||
TestDescriptor, | ||
{ | ||
#[serde(rename = "callableName")] |
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.
The serializable_type!
macro puts #[serde(rename_all = "camelCase")]
over the struct definition so the properties should automatically be camel cased, so you don't need this attribute. Hopefully.
} | ||
|
||
#[wasm_bindgen] | ||
pub fn get_test_callables(config: ProgramConfig) -> Result<Vec<ITestDescriptor>, String> { |
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.
Dead code?
|
||
#[wasm_bindgen] | ||
extern "C" { | ||
#[wasm_bindgen(typescript_type = "(callables: [string, ILocation][]) => void")] |
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.
Use the ITestCallable
type you already defined in the other wasm file, instead of the [string, ILocation]
tuple. Tuples are clunky in TS.
@@ -26,8 +26,7 @@ import { | |||
} from "../workers/common.js"; | |||
type QscWasm = typeof import("../../lib/web/qsc_wasm.js"); | |||
|
|||
// Only one event type for now | |||
export type LanguageServiceEvent = { | |||
export type LanguageServiceDiagnosticEvent = { |
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.
Wow I had totally forgotten that diagnostics were Event
s at this layer. I'm so happy/relieved to rediscover this. Since we're not plumbing callback arguments through seven layers of JavaScript, it's not going to be a QCOM breaking change :)
@@ -274,6 +285,18 @@ export class QSharpLanguageService implements ILanguageService { | |||
log.error("Error in onDiagnostics", e); | |||
} | |||
} | |||
|
|||
async onTestCallables(callables: [string, ILocation][]) { |
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.
As mentioned in the WASM layer, I think this type can be ITestCallables
instead of a tuple, the reasoning being that objects are just easier to use/read in JavaScript
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.
I think the changes in this file are dead code now.
let test_callables_callback = move |update: TestCallables| { | ||
let callables = update | ||
.callables | ||
.iter() |
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.
You can .into_iter()
this and avoid cloning the contents.
This PR rewrites #2059 to trigger test discovery from within the language server, as opposed to externally in an entirely separate context. Please read the description in that PR for more detail.
It also adds tests for LS state in both the Rust-based LS tests and the JS-based
basics.js
npm API tests.