<commit_before>import { Definition, DefinitionProvider, Location, Position, TextDocument, Uri } from 'vscode';
import { Server } from './server';
import { CodePointPosition } from './utils/utf16Position';

export class LeanDefinitionProvider implements DefinitionProvider {
    server: Server;

    constructor(server: Server) {
        this.server = server;
    }

    async provideDefinition(document: TextDocument, position: Position): Promise<Definition> {
        const codePointPosition = CodePointPosition.ofPosition(document, position);
        const response = await this.server.info(document.fileName, codePointPosition.line + 1, codePointPosition.character);
        if (response.record && response.record.source) {
            const src = response.record.source;
            const uri = src.file ? Uri.file(src.file) : document.uri;
            const pos = new CodePointPosition(src.line - 1, src.column);
            return new Location(uri, pos.toPosition(document));
        } else {
            return null;
        }
    }
}<commit_msg>fix: resolve position in correct document<commit_after>import { Definition, DefinitionProvider, Location, Position, TextDocument, Uri, workspace } from 'vscode';
import { Server } from './server';
import { CodePointPosition } from './utils/utf16Position';

export class LeanDefinitionProvider implements DefinitionProvider {
    server: Server;

    constructor(server: Server) {
        this.server = server;
    }

    async provideDefinition(document: TextDocument, position: Position): Promise<Definition> {
        const codePointPosition = CodePointPosition.ofPosition(document, position);
        const response = await this.server.info(document.fileName, codePointPosition.line + 1, codePointPosition.character);
        if (response.record && response.record.source) {
            const src = response.record.source;
            const uri = src.file ? Uri.file(src.file) : document.uri;
            const pos = new CodePointPosition(src.line - 1, src.column);
            return new Location(uri, pos.toPosition(await workspace.openTextDocument(uri)));
        } else {
            return null;
        }
    }
}
{'fraction_non_alphanumeric': 0.10257589696412144, 'fraction_numerical': 0.0036798528058877645, 'mean_word_length': 3.2563600782778863, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6914175', 'n_tokens_mistral': 552, 'n_tokens_neox': 539, 'n_words': 145}