<commit_before>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import AbstractSupport from './abstractProvider';
import { OmniSharpServer } from '../omnisharp/server';
import OptionProvider from '../observers/OptionProvider';
import * as protocol from '../omnisharp/protocol';
import * as serverUtils from '../omnisharp/utils';
import { toRange } from '../omnisharp/typeConversion';
import { CancellationToken, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind, Location } from 'vscode';
import { LanguageMiddlewareFeature } from '../omnisharp/LanguageMiddlewareFeature';
import SourceGeneratedDocumentProvider from './sourceGeneratedDocumentProvider';


export default class OmnisharpWorkspaceSymbolProvider extends AbstractSupport implements WorkspaceSymbolProvider {

    constructor(
        server: OmniSharpServer,
        private optionProvider: OptionProvider,
        languageMiddlewareFeature: LanguageMiddlewareFeature,
        private sourceGeneratedDocumentProvider: SourceGeneratedDocumentProvider) {
        super(server, languageMiddlewareFeature);
    }

    public async provideWorkspaceSymbols(search: string, token: CancellationToken): Promise<SymbolInformation[]> {

        let options = this.optionProvider.GetLatestOptions();
        let minFilterLength = options.minFindSymbolsFilterLength > 0 ? options.minFindSymbolsFilterLength : undefined;
        let maxItemsToReturn = options.maxFindSymbolsItems > 0 ? options.maxFindSymbolsItems : undefined;

        if (minFilterLength != undefined && search.length < minFilterLength) {
            return [];
        }

        try {
            let res = await serverUtils.findSymbols(this._server, { Filter: search, MaxItemsToReturn: maxItemsToReturn, FileName: '' }, token);
            if (res && Array.isArray(res.QuickFixes)) {
                return res.QuickFixes.map(symbol => this._asSymbolInformation(symbol));
            }
        }
        catch (error) {
            return [];
        }
    }

    private _asSymbolInformation(symbolInfo: protocol.SymbolLocation): SymbolInformation {
        let uri: Uri;
        if (symbolInfo.GeneratedFileInfo) {
            uri = this.sourceGeneratedDocumentProvider.addSourceGeneratedFileWithoutInitialContent(symbolInfo.GeneratedFileInfo, symbolInfo.FileName);
        }
        else {
            uri = Uri.file(symbolInfo.FileName);
        }

        const location = new Location(uri, toRange(symbolInfo));

        return new SymbolInformation(
            symbolInfo.Text,
            OmnisharpWorkspaceSymbolProvider._toKind(symbolInfo),
            symbolInfo.ContainingSymbolName ?? "",
            location);
    }

    private static _toKind(symbolInfo: protocol.SymbolLocation): SymbolKind {
        switch (symbolInfo.Kind) {
            case 'Method':
                return SymbolKind.Method;
            case 'Field':
                return SymbolKind.Field;
            case 'Property':
                return SymbolKind.Property;<commit_msg>Always return empty array as fallback<commit_after>/*---------------------------------------------------------------------------------------------
 *  Copyright (c) Microsoft Corporation. All rights reserved.
 *  Licensed under the MIT License. See License.txt in the project root for license information.
 *--------------------------------------------------------------------------------------------*/

import AbstractSupport from './abstractProvider';
import { OmniSharpServer } from '../omnisharp/server';
import OptionProvider from '../observers/OptionProvider';
import * as protocol from '../omnisharp/protocol';
import * as serverUtils from '../omnisharp/utils';
import { toRange } from '../omnisharp/typeConversion';
import { CancellationToken, Uri, WorkspaceSymbolProvider, SymbolInformation, SymbolKind, Location } from 'vscode';
import { LanguageMiddlewareFeature } from '../omnisharp/LanguageMiddlewareFeature';
import SourceGeneratedDocumentProvider from './sourceGeneratedDocumentProvider';


export default class OmnisharpWorkspaceSymbolProvider extends AbstractSupport implements WorkspaceSymbolProvider {

    constructor(
        server: OmniSharpServer,
        private optionProvider: OptionProvider,
        languageMiddlewareFeature: LanguageMiddlewareFeature,
        private sourceGeneratedDocumentProvider: SourceGeneratedDocumentProvider) {
        super(server, languageMiddlewareFeature);
    }

    public async provideWorkspaceSymbols(search: string, token: CancellationToken): Promise<SymbolInformation[]> {

        const options = this.optionProvider.GetLatestOptions();
        const minFilterLength = options.minFindSymbolsFilterLength > 0 ? options.minFindSymbolsFilterLength : undefined;
        const maxItemsToReturn = options.maxFindSymbolsItems > 0 ? options.maxFindSymbolsItems : undefined;

        if (minFilterLength !== undefined && search.length < minFilterLength) {
            return [];
        }

        try {
            const res = await serverUtils.findSymbols(this._server, { Filter: search, MaxItemsToReturn: maxItemsToReturn, FileName: '' }, token);
            if (Array.isArray(res?.QuickFixes)) {
                return res.QuickFixes.map(symbol => this._asSymbolInformation(symbol));
            }
        }
        catch {}

        return [];
    }

    private _asSymbolInformation(symbolInfo: protocol.SymbolLocation): SymbolInformation {
        let uri: Uri;
        if (symbolInfo.GeneratedFileInfo) {
            uri = this.sourceGeneratedDocumentProvider.addSourceGeneratedFileWithoutInitialContent(symbolInfo.GeneratedFileInfo, symbolInfo.FileName);
        }
        else {
            uri = Uri.file(symbolInfo.FileName);
        }

        const location = new Location(uri, toRange(symbolInfo));

        return new SymbolInformation(
            symbolInfo.Text,
            OmnisharpWorkspaceSymbolProvider._toKind(symbolInfo),
            symbolInfo.ContainingSymbolName ?? "",
            location);
    }

    private static _toKind(symbolInfo: protocol.SymbolLocation): SymbolKind {
        switch (symbolInfo.Kind) {
            case 'Method':
                return SymbolKind.Method;
            case 'Field':
                return SymbolKind.Field;
            case 'Property':
                return SymbolKind.Property;
{'fraction_non_alphanumeric': 0.1380354169819888, 'fraction_numerical': 0.0006054184955350386, 'mean_word_length': 2.5280298985584624, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 11, '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': '3855852', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1479, 'n_words': 362}