Skip to content

Commit

Permalink
fix of the type error
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Nov 1, 2024
1 parent 6c8acc3 commit 1313645
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 10 deletions.
7 changes: 6 additions & 1 deletion Editor/Rstudio.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ declare namespace rstudio {
function setup(): void;
}
declare namespace rstudio.tooltip {
function create_tooltip(model: monaco.editor.ITextModel, position: monaco.Position): Promise<unknown>;
function create_tooltip(model: monaco.editor.ITextModel, position: monaco.Position): any;
function contentHtml(word: string): string;
const imports_keyword: string;
const return_keyword: string;
const list_keyword: string;
const logical_keyword: string;
const keywords: {
imports: string;
return: string;
list: string;
TRUE: string;
FALSE: string;
};
}
20 changes: 17 additions & 3 deletions Editor/Rstudio.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Editor/Rstudio.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions Editor/rstudio/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,19 @@ module rstudio {
*/
let editor: monaco.editor.IStandaloneCodeEditor;
let demo_r = `
imports "aaa" from "bbb";
imports "JSON" from "base";
let f(x) = console.log("Hello world!");
let hello_world = function(x) {
return \`hello \${x}!\`;
};
print(c(1,2,3,4,5));
str(list(
a = 123,
b = [TRUE, TRUE, FALSE],
c = "XXX"
));
`;

export function create() {
Expand Down
22 changes: 19 additions & 3 deletions Editor/rstudio/rstudio/tooltip.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
module rstudio.tooltip {

export function create_tooltip(model: monaco.editor.ITextModel, position: monaco.Position) {
export function create_tooltip(model: monaco.editor.ITextModel, position: monaco.Position): any {
// 获取光标位置的单词
const word = model.getWordAtPosition(position);

if (!word) {
return null;
} else {
console.log(model);
console.log(position);
return new Promise((resolve, reject) => {
resolveTooltip(word, position, resolve);
});
}
}

function resolveTooltip(word: monaco.editor.IWordAtPosition, position: monaco.Position, resolve: (value: any) => void) {
function resolveTooltip(word: monaco.editor.IWordAtPosition, position: monaco.Position, resolve: <T>(value: T) => void) {
// 根据单词显示自定义提示
const hoverContent = contentHtml(word.word);
const htmlContent = {
Expand Down Expand Up @@ -59,8 +61,22 @@ module rstudio.tooltip {
(The expression is evaluated as soon as return is called, in the evaluation frame of the function and before any on.exit expression is evaluated.)
If the end of a function is reached without calling return, the value of the last evaluated expression is returned.`);

export const list_keyword = tooltip(
"Lists - Generic and Dotted Pairs",
`Functions to construct, coerce and check for both kinds of <code>R</code> lists.`);

export const logical_keyword = tooltip(
"Logical Vectors",
`Create or test for objects of type 'logical', and the basic logical constants.
TRUE and FALSE are reserved words denoting logical constants in the R language, whereas T and F are global variables whose initial values set to these.
All four are logical(1) vectors.
Logical vectors are coerced to integer vectors in contexts where a numerical value is required, with TRUE being mapped to 1L, FALSE to 0L and NA to NA_integer_.`);

export const keywords = {
"imports": imports_keyword,
'return': return_keyword
'return': return_keyword,
'list': list_keyword,
'TRUE': logical_keyword,
'FALSE': logical_keyword
};
}

0 comments on commit 1313645

Please sign in to comment.