Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
47 changes: 47 additions & 0 deletions Public/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,38 @@ export class App {
} else {
promise.fulfill();
}
break;
Comment on lines 122 to +125
case "signatureHelp": {
if (!promise) {
return;
}
if (response.value && response.value.signatures) {
const signatures = response.value.signatures.map((sig) => ({
label: sig.label,
documentation: sig.documentation
? sig.documentation.value ?? sig.documentation
: undefined,
parameters: (sig.parameters || []).map((parameter) => ({
label: parameter.label,
documentation: parameter.documentation
? parameter.documentation.value ?? parameter.documentation
: undefined,
})),
activeParameter: sig.activeParameter,
}));
promise.fulfill({
value: {
signatures: signatures,
activeSignature: response.value.activeSignature ?? 0,
activeParameter: response.value.activeParameter ?? 0,
},
dispose: () => {},
});
} else {
promise.fulfill();
}
break;
Comment on lines +152 to +155
}
case "diagnostics":
this.updateLanguageServerStatus(true);
this.editor.clearMarkers();
Expand Down Expand Up @@ -229,6 +261,21 @@ export class App {
return promise;
};

this.editor.onsignaturehelp = (position) => {
if (!languageServer.isReady) {
return;
}

sequence++;
const row = position.lineNumber - 1;
const column = position.column - 1;
languageServer.requestSignatureHelp(sequence, row, column);

return new Promise((fulfill, reject) => {
promises[sequence] = { fulfill: fulfill, reject: reject };
});
};

this.editor.focus();
this.editor.scrollToBottm();

Expand Down
26 changes: 25 additions & 1 deletion Public/js/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,40 @@ export class Editor {
},
});

// Trigger completion after "." as well as after these characters, which
// commonly start a new identifier/argument in Swift.
monaco.languages.registerCompletionItemProvider("swift", {
triggerCharacters: ["."],
triggerCharacters: [".", "(", ":", "<", " ", ","],
provideCompletionItems: (model, position) => {
return this.oncompletion(position);
Comment on lines 41 to 44
},
});

// Parameter hints (Xcode-style): pops up the function signature with the
// active argument highlighted when typing "(" or ",".
monaco.languages.registerSignatureHelpProvider("swift", {
signatureHelpTriggerCharacters: ["(", ","],
signatureHelpRetriggerCharacters: [",", ")"],
provideSignatureHelp: (model, position) => {
return this.onsignaturehelp(position);
},
});

// Explicit Ctrl+Space to trigger completion, like Xcode. (Cmd+Space is
// taken by Spotlight on macOS, so bind WinCtrl = the Control key.)
this.editor.addAction({
id: "trigger-suggest",
label: "Trigger Suggest",
keybindings: [monaco.KeyMod.WinCtrl | monaco.KeyCode.Space],
run: (ed) => {
ed.trigger("keyboard", "editor.action.triggerSuggest", {});
},
});

this.onchange = () => {};
this.onhover = () => {};
this.oncompletion = () => {};
this.onsignaturehelp = () => {};
this.onaction = () => {};
}

Expand Down
11 changes: 11 additions & 0 deletions Public/js/language_server.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ export class LanguageServer {
this.connection.send(JSON.stringify(params));
}

requestSignatureHelp(sequence, row, column) {
const params = {
method: "signatureHelp",
id: sequence,
row: row,
column: column,
sessionId: this.sessionId,
};
this.connection.send(JSON.stringify(params));
}

requestFormat(code) {
const params = {
method: "format",
Expand Down
6 changes: 6 additions & 0 deletions Public/js/main_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ export class MainView {
wordWrap: "on",
wrappingIndent: "indent",
tabSize: 2,
// Make completion pop up while typing (not only after "."), with no
// delay, and allow Tab to accept. Ctrl+Space still triggers it manually.
quickSuggestions: { other: true, comments: false, strings: false },
quickSuggestionsDelay: 0,
suggestOnTriggerCharacters: true,
tabCompletion: "on",
lightbulb: {
enabled: true,
},
Expand Down