Skip to content

Commit

Permalink
fix: compile error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
life2015 committed May 24, 2024
1 parent 064e050 commit dd4e0a1
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 54 deletions.
2 changes: 1 addition & 1 deletion configs/ts/tsconfig.base.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@
"allowSyntheticDefaultImports": true,
"jsx": "react",
"lib": ["dom", "esnext", "webworker"],
"typeRoots": ["../../node_modules/@types", "../../typings"]
"typeRoots": ["../../node_modules/@types", "../../typings", "../../node_modules/@withfig"]
}
}
1 change: 1 addition & 0 deletions packages/terminal-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"@opensumi/ide-variable": "workspace:*",
"@opensumi/ide-workspace": "workspace:*",
"@types/http-proxy": "^1.17.2",
"@withfig/autocomplete-types": "^1.28.0",
"http-proxy": "^1.18.0"
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
/* eslint-disable no-console */
import React from 'react';
import ReactDOM from 'react-dom';
import { IDecoration, IDisposable, IMarker, Terminal } from 'xterm';

import { Autowired, Injectable } from '@opensumi/di';
import { Disposable, Emitter, FileType, Uri } from '@opensumi/ide-core-common';
import { DiskFileServicePath, IDiskFileProvider } from '@opensumi/ide-file-service';
import {
ITerminalConnection,
ITerminalController,
} from '@opensumi/ide-terminal-next';

import { ITerminalController } from '../../common/controller';
import { ITerminalConnection } from '../../common/index';
import { TerminalIntellCommandController } from '../component/terminal-intell-command-controller';

import { getSuggestions } from './runtime/runtime';
Expand All @@ -22,7 +21,7 @@ import { fsAsyncStub } from './runtime/template';
enum IstermOscPt {
PromptStarted = 'PS',
PromptEnded = 'PE',
CurrentWorkingDirectory = 'CWD'
CurrentWorkingDirectory = 'CWD',
}

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

public active() {
this.disposables.push(
this.terminalController.onDidOpenTerminal(({ id }) =>
this.listenTerminalEvent(id),
),
);
this.disposables.push(this.terminalController.onDidOpenTerminal(({ id }) => this.listenTerminalEvent(id)));
}

private listenTerminalEvent(clientId: string) {
Expand Down Expand Up @@ -112,8 +107,6 @@ export class IntellTerminalService extends Disposable {
this.onDataDisposable.dispose();
}

window.getSuggestions = getSuggestions;

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

const lineData = buffer.getLine(this.promptEndMarker?.line || 0);
const lineDataString = lineData?.translateToString(
false,
xOffset2,
cursorX,
);
const lineDataString = lineData?.translateToString(false, xOffset2, cursorX);
console.log('lineDataString', lineDataString);

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

if (lineDataString && this.promptEndMarker) {

fsAsyncStub.setProxy({
readdir: async (cwd: string, options: { withFileTypes: true }) => {
const res = await this.diskFileProvider.readDirectory(Uri.file(cwd));
const files = res.map(([name, type]) => ({
name,
isFile: () => type === FileType.File,
isDirectory: () => type === FileType.Directory,
}));
name,
isFile: () => type === FileType.File,
isDirectory: () => type === FileType.Directory,
}));
console.log('readdir', cwd, options, res, files);
return files;
},

});

const suggestionBlob = await getSuggestions(
lineDataString,
'/home/admin/retrox.jcy/cloud-ide/api-server',
);

console.log(
'suggestionBlob',
suggestionBlob,
'lineDataString',
JSON.stringify(lineDataString),
);
const suggestionBlob = await getSuggestions(lineDataString, '/home/admin/retrox.jcy/cloud-ide/api-server');

console.log('suggestionBlob', suggestionBlob, 'lineDataString', JSON.stringify(lineDataString));
this.promptEndDecoration?.dispose();

if (suggestionBlob && suggestionBlob.suggestions) {
Expand All @@ -237,10 +216,12 @@ export class IntellTerminalService extends Disposable {
x: cursorX,
});
console.log('render termianl intell react component');
const suggestionsViewModel = [...suggestionBlob.suggestions.map((suggestion) => ({
const suggestionsViewModel = [
...suggestionBlob.suggestions.map((suggestion) => ({
description: suggestion.description || '',
command: suggestion.name,
}))];
})),
];
this.promptEndDecoration?.onRender((element) => {
ReactDOM.render(
<TerminalIntellCommandController
Expand Down
53 changes: 36 additions & 17 deletions packages/terminal-next/src/browser/intell/runtime/generator.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,64 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/quotes */
/* eslint-disable arrow-body-style */

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import log from "../utils/log";
import { runTemplates } from "./template";
import log from '../utils/log';

import { runTemplates } from './template';
// import { buildExecuteShellCommand } from "./utils.js";

const getGeneratorContext = (cwd: string): Fig.GeneratorContext => {
return {
environmentVariables: Object.fromEntries(Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] != null)),
environmentVariables: Object.fromEntries(
Object.entries(process.env).filter((entry): entry is [string, string] => entry[1] != null),
),
currentWorkingDirectory: cwd,
currentProcess: "", // TODO: define current process
sshPrefix: "", // deprecated, should be empty
currentProcess: '', // TODO: define current process
sshPrefix: '', // deprecated, should be empty
isDangerous: false,
searchTerm: "", // TODO: define search term
searchTerm: '', // TODO: define search term
};
};

const buildExecuteShellCommand = (args: any): any => {
console.error("buildExecuteShellCommand not implemented", args);
console.error('buildExecuteShellCommand not implemented', args);
// throw new Error("Function not implemented.");
return (shellInput: any) => {
console.log('shellInput', shellInput);
return {
stdout: ''
}
}
}
stdout: '',
};
};
};

// TODO: add support for caching, trigger, & getQueryTerm
export const runGenerator = async (generator: Fig.Generator, tokens: string[], cwd: string): Promise<Fig.Suggestion[]> => {
export const runGenerator = async (
generator: Fig.Generator,
tokens: string[],
cwd: string,
): Promise<Fig.Suggestion[]> => {
// TODO: support trigger
const { script, postProcess, scriptTimeout, splitOn, custom, template, filterTemplateSuggestions } = generator;
console.log("runGenerator", { script, postProcess, scriptTimeout, splitOn, custom, template, filterTemplateSuggestions });
console.log('runGenerator', {
script,
postProcess,
scriptTimeout,
splitOn,
custom,
template,
filterTemplateSuggestions,
});

const executeShellCommand = buildExecuteShellCommand(scriptTimeout ?? 5000);
const suggestions = [];
const suggestions: Fig.Suggestion[] = [];
try {
if (script) {
const shellInput = typeof script === "function" ? script(tokens) : script;
const shellInput = typeof script === 'function' ? script(tokens) : script;
const scriptOutput = Array.isArray(shellInput)
? await executeShellCommand({ command: shellInput.at(0) ?? "", args: shellInput.slice(1) })
? await executeShellCommand({ command: shellInput.at(0) ?? '', args: shellInput.slice(1) })
: await executeShellCommand(shellInput);

if (postProcess) {
Expand Down Expand Up @@ -67,7 +86,7 @@ export const runGenerator = async (generator: Fig.Generator, tokens: string[], c
}
return suggestions;
} catch (e) {
log.debug({ msg: "generator failed", e, script, splitOn, template });
log.debug({ msg: 'generator failed', e, script, splitOn, template });
}
return suggestions;
};
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2960,6 +2960,7 @@ __metadata:
"@opensumi/ide-variable": "workspace:*"
"@opensumi/ide-workspace": "workspace:*"
"@types/http-proxy": "npm:^1.17.2"
"@withfig/autocomplete-types": "npm:^1.28.0"
http-proxy: "npm:^1.18.0"
node-pty: "npm:1.0.0"
os-locale: "npm:^4.0.0"
Expand Down Expand Up @@ -4745,6 +4746,13 @@ __metadata:
languageName: node
linkType: hard

"@withfig/autocomplete-types@npm:^1.28.0":
version: 1.31.0
resolution: "@withfig/autocomplete-types@npm:1.31.0"
checksum: 10/9468d9022f397934eb42b0c1ea485e71dbb90da127c1b27005c43dc15a63d77ff2202ce98f80ef027ea78e9c27f655ad91f9120dc0492c77f0604ab4687efde6
languageName: node
linkType: hard

"@xmldom/xmldom@npm:^0.8.8":
version: 0.8.10
resolution: "@xmldom/xmldom@npm:0.8.10"
Expand Down

0 comments on commit dd4e0a1

Please sign in to comment.