https://www.dendron.so/ logo
#chat
Title
a

AshSimmonds

07/03/2022, 9:40 AM
Anyone having any luck with copilot? Seems everyone else talks about amazing game-changing results - all I'm seeing is hot garbage that makes no sense.
What I provided:
Copy code
const arrayOfFiles = ['./docs/testefile01.md', './docs/testefile02.md']; 

// read files in arrayOfFiles and return the contents as a string in a JSON object
What I got - I suppose it's second-third-fifth-guessing what I wanted to achieve?
Copy code
export const getFiles = async (): Promise<string> => {
    const files = await Promise.all(arrayOfFiles.map(file => readFile(file, 'utf8')));
    return JSON.stringify(files);
}

// read file and return the contents as a string
export const getFile = async (file: string): Promise<string> => {
    const content = await readFile(file, 'utf8');
    return content;
}

// write file and return the contents as a string
export const writeFile = async (file: string, content: string): Promise<string> => {
    await writeFile(file, content);
    return content;
}

// delete file and return the contents as a string
export const deleteFile = async (file: string): Promise<string> => {
    await unlink(file);
    return file;
}

// rename file and return the contents as a string
export const renameFile = async (file: string, newFile: string): Promise<string> => {
    await rename(file, newFile);
    return newFile;
}

// copy file and return the contents as a string
export const copyFile = async (file: string, newFile: string): Promise<string> => {
    await copyFile(file, newFile);
    return newFile;
}

// move file and return the contents as a string
export const moveFile = async (file: string, newFile: string): Promise<string> => {
    await move(file, newFile);
    return newFile;
}

// read directory and return the contents as a string
export const getDirectory = async (dir: string): Promise<string> => {
    const content = await readdir(dir);
    return JSON.stringify(content);
}

// create directory and return the contents as a string
export const createDirectory = async (dir: string): Promise<string> => {
    await mkdir(dir);
    return dir;
}

// delete directory and return the contents as a string
export const deleteDirectory = async (dir: string): Promise<string> => {
    await rmdir(
So I stripped out only the first response, added a handler for the API (using Deno Fresh), and uh, it worked well enough. Full file:
Copy code
const arrayOfFiles = ['./docs/testefile01.md', './docs/testefile02.md'];

// read files in arrayOfFiles and return the contents as a string in a JSON object

export const getFiles = async (): Promise<string> => {
    const files = await Promise.all(arrayOfFiles.map(file => Deno.readTextFile(file)));
    return JSON.stringify(files);
}

export const handler = async (theRequest: Request): Promise<Response> => {

    const theFilesOutput = getFiles();

    return new Response(await theFilesOutput);
};
And here's the API response, which as you can tell is just two short markdown files concatenated:
Copy code
["# it's a copilot teste  \r\n  \r\nCan this thing actually do stuff?\r\n\r\n## Dunno\r\n","# still testing  \r\n  \r\nare we getting somewhere?\r\n\r\n## maybe\r\n"]
Soooo yeah, this async/await stuff in Deno Fresh I'd been banging my head a bit coming from mostly dotnet for my async processing, and it pretty much solved it. Not even sure where I was going wrong, probably just a
promise
in the wrong spot or something. Anyhoo, I'm suddenly more optimistic - and as they say, it all comes down to giving good very specific instructions, and let Copilot suss out the syntax.
k

kfischer_okarin

07/04/2022, 10:03 AM
I use it since last year October... And I really like it a lot.... You just need to use it correctly.... If for example almost never use comment based completion... usually just starting writing methods with clear names - und often the suggestions is quite close to what I want.... Can I use it as is? In most cases no....
The smaller and atomic/independent the stuff is you want to write..... the better it will work
Having a habit of writing small single responsibility methods helps a lot 😄
a

AshSimmonds

07/05/2022, 5:04 AM
Actually loving copilot for simple stuff, this is as simple as it gets but when you're using 3-5 languages a day sometimes you lose context - I know exactly what I want to do and have done it in 20 other languages, but it'd take me 10-15 mins of messing around with minor syntax to get it right, so I just ask and get:
Copy code
// add '.md' to all files in arrayOfFiles that don't end in '.md'
    arrayOfFiles = arrayOfFiles.map(file => {
        if (!file.endsWith(".md")) {
            return file + ".md";
        }
        return file;
    }).sort();