Skip to content

Commit dd4e0a1

Browse files
committed
fix: compile error fix
1 parent 064e050 commit dd4e0a1

File tree

5 files changed

+63
-54
lines changed

5 files changed

+63
-54
lines changed

configs/ts/tsconfig.base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@
2525
"allowSyntheticDefaultImports": true,
2626
"jsx": "react",
2727
"lib": ["dom", "esnext", "webworker"],
28-
"typeRoots": ["../../node_modules/@types", "../../typings"]
28+
"typeRoots": ["../../node_modules/@types", "../../typings", "../../node_modules/@withfig"]
2929
}
3030
}

packages/terminal-next/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"@opensumi/ide-variable": "workspace:*",
4242
"@opensumi/ide-workspace": "workspace:*",
4343
"@types/http-proxy": "^1.17.2",
44+
"@withfig/autocomplete-types": "^1.28.0",
4445
"http-proxy": "^1.18.0"
4546
}
4647
}

packages/terminal-next/src/browser/intell/intell-terminal.service.tsx

Lines changed: 17 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
/* eslint-disable no-console */
12
import React from 'react';
23
import ReactDOM from 'react-dom';
34
import { IDecoration, IDisposable, IMarker, Terminal } from 'xterm';
45

56
import { Autowired, Injectable } from '@opensumi/di';
67
import { Disposable, Emitter, FileType, Uri } from '@opensumi/ide-core-common';
78
import { DiskFileServicePath, IDiskFileProvider } from '@opensumi/ide-file-service';
8-
import {
9-
ITerminalConnection,
10-
ITerminalController,
11-
} from '@opensumi/ide-terminal-next';
129

10+
import { ITerminalController } from '../../common/controller';
11+
import { ITerminalConnection } from '../../common/index';
1312
import { TerminalIntellCommandController } from '../component/terminal-intell-command-controller';
1413

1514
import { getSuggestions } from './runtime/runtime';
@@ -22,7 +21,7 @@ import { fsAsyncStub } from './runtime/template';
2221
enum IstermOscPt {
2322
PromptStarted = 'PS',
2423
PromptEnded = 'PE',
25-
CurrentWorkingDirectory = 'CWD'
24+
CurrentWorkingDirectory = 'CWD',
2625
}
2726

2827
@Injectable()
@@ -49,11 +48,7 @@ export class IntellTerminalService extends Disposable {
4948
private currentSessionId: string;
5049

5150
public active() {
52-
this.disposables.push(
53-
this.terminalController.onDidOpenTerminal(({ id }) =>
54-
this.listenTerminalEvent(id),
55-
),
56-
);
51+
this.disposables.push(this.terminalController.onDidOpenTerminal(({ id }) => this.listenTerminalEvent(id)));
5752
}
5853

5954
private listenTerminalEvent(clientId: string) {
@@ -112,8 +107,6 @@ export class IntellTerminalService extends Disposable {
112107
this.onDataDisposable.dispose();
113108
}
114109

115-
window.getSuggestions = getSuggestions;
116-
117110
// HACK: 这里拿去 TerminalConnection 的方式很 Hack,看看有没有更好的办法?
118111
// @ts-ignore
119112
const attachAddon = xterm._addonManager._addons.find((addon) => !!addon?.instance?.connection);
@@ -181,11 +174,7 @@ export class IntellTerminalService extends Disposable {
181174
const cursorY = buffer.cursorY;
182175

183176
const lineData = buffer.getLine(this.promptEndMarker?.line || 0);
184-
const lineDataString = lineData?.translateToString(
185-
false,
186-
xOffset2,
187-
cursorX,
188-
);
177+
const lineDataString = lineData?.translateToString(false, xOffset2, cursorX);
189178
console.log('lineDataString', lineDataString);
190179

191180
// 避免 上下方向键导致重复渲染
@@ -199,32 +188,22 @@ export class IntellTerminalService extends Disposable {
199188
}
200189

201190
if (lineDataString && this.promptEndMarker) {
202-
203191
fsAsyncStub.setProxy({
204192
readdir: async (cwd: string, options: { withFileTypes: true }) => {
205193
const res = await this.diskFileProvider.readDirectory(Uri.file(cwd));
206194
const files = res.map(([name, type]) => ({
207-
name,
208-
isFile: () => type === FileType.File,
209-
isDirectory: () => type === FileType.Directory,
210-
}));
195+
name,
196+
isFile: () => type === FileType.File,
197+
isDirectory: () => type === FileType.Directory,
198+
}));
211199
console.log('readdir', cwd, options, res, files);
212200
return files;
213201
},
214-
215202
});
216203

217-
const suggestionBlob = await getSuggestions(
218-
lineDataString,
219-
'/home/admin/retrox.jcy/cloud-ide/api-server',
220-
);
221-
222-
console.log(
223-
'suggestionBlob',
224-
suggestionBlob,
225-
'lineDataString',
226-
JSON.stringify(lineDataString),
227-
);
204+
const suggestionBlob = await getSuggestions(lineDataString, '/home/admin/retrox.jcy/cloud-ide/api-server');
205+
206+
console.log('suggestionBlob', suggestionBlob, 'lineDataString', JSON.stringify(lineDataString));
228207
this.promptEndDecoration?.dispose();
229208

230209
if (suggestionBlob && suggestionBlob.suggestions) {
@@ -237,10 +216,12 @@ export class IntellTerminalService extends Disposable {
237216
x: cursorX,
238217
});
239218
console.log('render termianl intell react component');
240-
const suggestionsViewModel = [...suggestionBlob.suggestions.map((suggestion) => ({
219+
const suggestionsViewModel = [
220+
...suggestionBlob.suggestions.map((suggestion) => ({
241221
description: suggestion.description || '',
242222
command: suggestion.name,
243-
}))];
223+
})),
224+
];
244225
this.promptEndDecoration?.onRender((element) => {
245226
ReactDOM.render(
246227
<TerminalIntellCommandController

packages/terminal-next/src/browser/intell/runtime/generator.ts

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,64 @@
1+
/* eslint-disable no-console */
2+
/* eslint-disable @typescript-eslint/quotes */
3+
/* eslint-disable arrow-body-style */
4+
15
// Copyright (c) Microsoft Corporation.
26
// Licensed under the MIT License.
37

4-
import log from "../utils/log";
5-
import { runTemplates } from "./template";
8+
import log from '../utils/log';
9+
10+
import { runTemplates } from './template';
611
// import { buildExecuteShellCommand } from "./utils.js";
712

813
const getGeneratorContext = (cwd: string): Fig.GeneratorContext => {
914
return {
10-
environmentVariables: Object.fromEntries(Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] != null)),
15+
environmentVariables: Object.fromEntries(
16+
Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] != null),
17+
),
1118
currentWorkingDirectory: cwd,
12-
currentProcess: "", // TODO: define current process
13-
sshPrefix: "", // deprecated, should be empty
19+
currentProcess: '', // TODO: define current process
20+
sshPrefix: '', // deprecated, should be empty
1421
isDangerous: false,
15-
searchTerm: "", // TODO: define search term
22+
searchTerm: '', // TODO: define search term
1623
};
1724
};
1825

1926
const buildExecuteShellCommand = (args: any): any => {
20-
console.error("buildExecuteShellCommand not implemented", args);
27+
console.error('buildExecuteShellCommand not implemented', args);
2128
// throw new Error("Function not implemented.");
2229
return (shellInput: any) => {
2330
console.log('shellInput', shellInput);
2431
return {
25-
stdout: ''
26-
}
27-
}
28-
}
32+
stdout: '',
33+
};
34+
};
35+
};
2936

3037
// TODO: add support for caching, trigger, & getQueryTerm
31-
export const runGenerator = async (generator: Fig.Generator, tokens: string[], cwd: string): Promise<Fig.Suggestion[]> => {
38+
export const runGenerator = async (
39+
generator: Fig.Generator,
40+
tokens: string[],
41+
cwd: string,
42+
): Promise<Fig.Suggestion[]> => {
3243
// TODO: support trigger
3344
const { script, postProcess, scriptTimeout, splitOn, custom, template, filterTemplateSuggestions } = generator;
34-
console.log("runGenerator", { script, postProcess, scriptTimeout, splitOn, custom, template, filterTemplateSuggestions });
45+
console.log('runGenerator', {
46+
script,
47+
postProcess,
48+
scriptTimeout,
49+
splitOn,
50+
custom,
51+
template,
52+
filterTemplateSuggestions,
53+
});
3554

3655
const executeShellCommand = buildExecuteShellCommand(scriptTimeout ?? 5000);
37-
const suggestions = [];
56+
const suggestions: Fig.Suggestion[] = [];
3857
try {
3958
if (script) {
40-
const shellInput = typeof script === "function" ? script(tokens) : script;
59+
const shellInput = typeof script === 'function' ? script(tokens) : script;
4160
const scriptOutput = Array.isArray(shellInput)
42-
? await executeShellCommand({ command: shellInput.at(0) ?? "", args: shellInput.slice(1) })
61+
? await executeShellCommand({ command: shellInput.at(0) ?? '', args: shellInput.slice(1) })
4362
: await executeShellCommand(shellInput);
4463

4564
if (postProcess) {
@@ -67,7 +86,7 @@ export const runGenerator = async (generator: Fig.Generator, tokens: string[], c
6786
}
6887
return suggestions;
6988
} catch (e) {
70-
log.debug({ msg: "generator failed", e, script, splitOn, template });
89+
log.debug({ msg: 'generator failed', e, script, splitOn, template });
7190
}
7291
return suggestions;
7392
};

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2960,6 +2960,7 @@ __metadata:
29602960
"@opensumi/ide-variable": "workspace:*"
29612961
"@opensumi/ide-workspace": "workspace:*"
29622962
"@types/http-proxy": "npm:^1.17.2"
2963+
"@withfig/autocomplete-types": "npm:^1.28.0"
29632964
http-proxy: "npm:^1.18.0"
29642965
node-pty: "npm:1.0.0"
29652966
os-locale: "npm:^4.0.0"
@@ -4745,6 +4746,13 @@ __metadata:
47454746
languageName: node
47464747
linkType: hard
47474748

4749+
"@withfig/autocomplete-types@npm:^1.28.0":
4750+
version: 1.31.0
4751+
resolution: "@withfig/autocomplete-types@npm:1.31.0"
4752+
checksum: 10/9468d9022f397934eb42b0c1ea485e71dbb90da127c1b27005c43dc15a63d77ff2202ce98f80ef027ea78e9c27f655ad91f9120dc0492c77f0604ab4687efde6
4753+
languageName: node
4754+
linkType: hard
4755+
47484756
"@xmldom/xmldom@npm:^0.8.8":
47494757
version: 0.8.10
47504758
resolution: "@xmldom/xmldom@npm:0.8.10"

0 commit comments

Comments
 (0)