当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript IConnection.onCompletion方法代码示例

本文整理汇总了TypeScript中vscode-languageserver.IConnection.onCompletion方法的典型用法代码示例。如果您正苦于以下问题:TypeScript IConnection.onCompletion方法的具体用法?TypeScript IConnection.onCompletion怎么用?TypeScript IConnection.onCompletion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在vscode-languageserver.IConnection的用法示例。

在下文中一共展示了IConnection.onCompletion方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: constructor

  constructor(
      protected connection: IConnection,
      private converter: AnalyzerLSPConverter,
      private featureFinder: FeatureFinder, private analyzer: LsAnalyzer,
      private capabilities: ClientCapabilities) {
    super();

    this.clientSupportsSnippets =
        !!(this.capabilities.textDocument &&
           this.capabilities.textDocument.completion &&
           this.capabilities.textDocument.completion.completionItem &&
           this.capabilities.textDocument.completion.completionItem
               .snippetSupport);

    // Work around https://github.com/atom/atom-languageclient/issues/150
    const ourExperimentalCapabilities = this.capabilities.experimental &&
        this.capabilities.experimental['polymer-ide'];
    this.clientCannotFilter = ourExperimentalCapabilities ?
        !!ourExperimentalCapabilities.doesNotFilterCompletions :
        false;

    this.connection.onCompletion(async(request) => {
      const result = await this.handleErrors(
          this.autoComplete(request), {isIncomplete: true, items: []});
      return result;
    });
  }
开发者ID:asdfg9822,项目名称:polymer-editor-service,代码行数:27,代码来源:auto-completer.ts


示例2: constructor

  constructor(
      protected connection: IConnection,
      private converter: AnalyzerLSPConverter,
      private featureFinder: FeatureFinder, private analyzer: LsAnalyzer,
      private capabilities: ClientCapabilities) {
    super();

    const completionCapabilities =
        (this.capabilities.textDocument &&
         this.capabilities.textDocument.completion) ||
        {};

    const completionItemCapabilities =
        completionCapabilities.completionItem || {};

    this.clientSupportsSnippets = !!completionItemCapabilities.snippetSupport;

    this.preferredDocumentationFormat = 'plaintext';
    const preferredFormats =
        completionItemCapabilities.documentationFormat || ['plaintext'];
    for (const preferredFormat of preferredFormats) {
      if (preferredFormat === 'plaintext' || preferredFormat === 'markdown') {
        this.preferredDocumentationFormat = preferredFormat;
        break;
      }
    }

    // Work around https://github.com/atom/atom-languageclient/issues/150
    const ourExperimentalCapabilities = this.capabilities.experimental &&
        this.capabilities.experimental['polymer-ide'];
    this.clientCannotFilter = ourExperimentalCapabilities ?
        !!ourExperimentalCapabilities.doesNotFilterCompletions :
        false;

    this.connection.onCompletion(async (request) => {
      const result = await this.handleErrors(
          this.autoComplete(request), {isIncomplete: true, items: []});
      return result;
    });
  }
开发者ID:Polymer,项目名称:tools,代码行数:40,代码来源:auto-completer.ts


示例3: getDocumentSettings

		let settings = await getDocumentSettings(textDocument, () => modes.some(m => !!m.doValidation));
		modes.forEach(mode => {
			if (mode.doValidation && isValidationEnabled(mode.getId(), settings)) {
				pushAll(diagnostics, mode.doValidation(textDocument, settings));
			}
		});
	}
	connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
}

connection.onCompletion(async textDocumentPosition => {
	let document = documents.get(textDocumentPosition.textDocument.uri);
	let mode = languageModes.getModeAtPosition(document, textDocumentPosition.position);
	if (mode && mode.doComplete) {
		if (mode.getId() !== 'html') {
			connection.telemetry.logEvent({ key: 'html.embbedded.complete', value: { languageId: mode.getId() } });
		}
		let settings = await getDocumentSettings(document, () => mode.doComplete.length > 2);
		return mode.doComplete(document, textDocumentPosition.position, settings);
	}
	return { isIncomplete: true, items: [] };
});

connection.onCompletionResolve(item => {
	let data = item.data;
	if (data && data.languageId && data.uri) {
		let mode = languageModes.getMode(data.languageId);
		let document = documents.get(data.uri);
		if (mode && mode.doResolve && document) {
			return mode.doResolve(document, item);
		}
	}
开发者ID:armanio123,项目名称:vscode,代码行数:32,代码来源:htmlServerMain.ts


示例4: validateTextDocument

}

function validateTextDocument(textDocument: TextDocument): void {
	let diagnostics: Diagnostic[] = [];
	languageModes.getAllModesInDocument(textDocument).forEach(mode => {
		if (mode.doValidation) {
			diagnostics = diagnostics.concat(mode.doValidation(textDocument));
		}
	});
	connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
}

connection.onCompletion(textDocumentPosition => {
	let document = documents.get(textDocumentPosition.textDocument.uri);
	let mode = languageModes.getModeAtPosition(document, textDocumentPosition.position);
	if (mode && mode.doComplete) {
		return mode.doComplete(document, textDocumentPosition.position);
	}
	return { isIncomplete: true, items: [] };
});

connection.onCompletionResolve(item => {
	let data = item.data;
	if (data && data.languageId && data.uri) {
		let mode = languageModes.getMode(data.languageId);
		let document = documents.get(data.uri);
		if (mode && mode.doResolve && document) {
			return mode.doResolve(document, item);
		}
	}
	return item;
});
开发者ID:,项目名称:,代码行数:32,代码来源:


示例5: initStylableLanguageService

export function initStylableLanguageService(
    connection: IConnection,
    services: { styl: Stylable; tsLanguageService: ExtendedTsLanguageService; requireModule: typeof require },
    fs: ExtendedFSReadSync,
    docsDispatcher: MinimalDocsDispatcher,
    _notifications: NotificationTypes
) {
    const provider = createProvider(services.styl, services.tsLanguageService);
    const processor = services.styl.fileProcessor;
    const newCssService = new CssService(fs);

    connection.onCompletion(
        (params: CompletionParams): CompletionItem[] => {
            const documentUri = params.textDocument.uri;
            const position = params.position;

            if (!documentUri.endsWith('.st.css') && !documentUri.startsWith('untitled:')) {
                return [];
            }

            const document = fs.get(documentUri);

            const res = provider.provideCompletionItemsFromSrc(
                document.getText(),
                {
                    line: position.line,
                    character: position.character
                },
                documentUri,
                fs
            );

            return res
                .map((com: Completion) => {
                    const lspCompletion: CompletionItem = CompletionItem.create(com.label);
                    const ted: TextEdit = TextEdit.replace(
                        com.range
                            ? com.range
                            : new ProviderRange(
                                  new ProviderPosition(position.line, Math.max(position.character - 1, 0)),
                                  position
                              ),
                        typeof com.insertText === 'string' ? com.insertText : com.insertText.source
                    );
                    lspCompletion.insertTextFormat = 2;
                    lspCompletion.detail = com.detail;
                    lspCompletion.textEdit = ted;
                    lspCompletion.sortText = com.sortText;
                    lspCompletion.filterText =
                        typeof com.insertText === 'string' ? com.insertText : com.insertText.source;
                    if (com.additionalCompletions) {
                        lspCompletion.command = Command.create('additional', 'editor.action.triggerSuggest');
                    } else if (com.triggerSignature) {
                        lspCompletion.command = Command.create('additional', 'editor.action.triggerParameterHints');
                    }
                    return lspCompletion;
                })
                .concat(newCssService.getCompletions(document, position));
        }
    );

    async function diagnose() {
        let res: any;
        let ignore = false;
        try {
            res = await connection.workspace.getConfiguration({
                section: 'stylable'
            });
            if (!!res && !!res.diagnostics && !!res.diagnostics.ignore && !!res.diagnostics.ignore.length) {
                ignore = true;
            }
        } catch (e) {
            /*Client has no workspace/configuration method, ignore silently */
        }

        docsDispatcher.keys!().forEach(key => {
            const doc = docsDispatcher.get!(key);
            if (!!doc) {
                if (doc.languageId === 'stylable') {
                    let diagnostics: Diagnostic[];
                    if (
                        ignore &&
                        (res.diagnostics.ignore as string[]).some(p => {
                            return fromVscodePath(doc.uri).startsWith(path.resolve(p));
                        })
                    ) {
                        diagnostics = [];
                    } else {
                        diagnostics = createDiagnosis(doc, processor, services.requireModule)
                            .map(diag => {
                                diag.source = 'stylable';
                                return diag;
                            })
                            .concat(newCssService.getDiagnostics(doc));
                    }
                    connection.sendDiagnostics({ uri: doc.uri, diagnostics });
                }
            }
        });
    }
//.........这里部分代码省略.........
开发者ID:wix,项目名称:stylable-intelligence,代码行数:101,代码来源:service.ts


示例6:

connection.onCompletion((textDocumentPosition: TextDocumentPositionParams): CompletionItem[] => {
	// The pass parameter contains the position of the text document in 
	// which code complete got requested. For the example we ignore this
	// info and always provide the same completion items.
	let file = textDocumentPosition.textDocument.uri.replace('%3A', ':').replace('file:///', '');

	let isWin = /^win/.test(process.platform);

	if (isWin) {
		file = file.charAt(0).toUpperCase() + file.slice(1);
	}
	else {
		file = '/' + file;
	}


	let document = documents.get(textDocumentPosition.textDocument.uri);
	let offset = document.offsetAt(textDocumentPosition.position);

	let text = document.getText();
	let pretext = 'require("';
	if (offset - pretext.length < 0) {
		return [];
	}

	let requireOffset = text.lastIndexOf(pretext, offset);
	let requireOffset2 = text.lastIndexOf(pretext.replace('"', "'"), offset);
	requireOffset = Math.max(requireOffset, requireOffset2);
	if (requireOffset < 0)
		return;


	let realOffset = text.lastIndexOf("'", offset - 1);
	let realOffset2 = text.lastIndexOf('"', offset - 1);
	realOffset = Math.max(realOffset, realOffset2);
	if (realOffset < 0 || realOffset !== requireOffset + 8)
		return [];

	if (text[offset] !== '"' && text[offset] !== "'")
		return [];
	if (document.positionAt(requireOffset).line !== textDocumentPosition.position.line)
		return [];

	let existingText = text.substring(realOffset + 1, offset);

	let result: NodeModuleCompletion[] = [];
	_.forEach(builtins, (b) => {
		if (!existingText.startsWith('.'))
			result.push(_.pick(b, ['label', 'kind', 'data']) as NodeModuleCompletion);
	});

	generateFromNodeModules(file, existingText);

	_.forEach(nodeModules, (m) => {
		result.push(_.pick(m, ['label', 'kind', 'data']) as NodeModuleCompletion);
	});

	generateFromLocal(file, existingText, realOffset + 1, document);

	_.forEach(localModules, (m) => {
		result.push(_.pick(m, ['label', 'kind', 'data', 'sortText']) as NodeModuleCompletion);
	});

	return result as CompletionItem[];
});
开发者ID:codyrigney92,项目名称:require-complete,代码行数:65,代码来源:server.ts


示例7: getTheseTokens

let xv: RegExp = /[$\w\d-]/g; // variable

let jwv: RegExp = /[\w\d]+/g;  // JS word or variable

function getTheseTokens(document: TextDocument, offset: number): string[] {
    let preceding = document.getText().slice(0, offset)
    let thisLine = preceding.slice(preceding.lastIndexOf('\n'))
    let theseTokens: string[] = thisLine.split(b)
    return theseTokens
};

connection.onCompletion((textDocumentPositionParams: TextDocumentPositionParams): CompletionItem[] => {
    let document = documents.get(textDocumentPositionParams.textDocument.uri)
    let lang = document.languageId || 'javascript'
    let offset = document.offsetAt(textDocumentPositionParams.position)

    return {
        'xquery-ml': completeXQuery,
        'javascript': completeSJS
    }[lang](document, offset)
})

function completeXQuery(document: TextDocument, offset: number): CompletionItem[] {
    let allCompletions: CompletionItem[] = [];
    let theseTokens = getTheseTokens(document, offset)

    // shortcircuit: don't complete on dot in XQuery
    if (theseTokens.slice(-1)[0] === ".") {return allCompletions}

    else if (theseTokens.slice(-1)[0] === ":" && theseTokens.slice(-2)[0].match(jwv)) {
        let namespace: string = theseTokens.slice(-2)[0]
        allCompletions = allCompletions.concat(allMlXqyFunctions(namespace))
开发者ID:mikrovvelle,项目名称:mlxprs,代码行数:32,代码来源:server.ts


示例8: handleOnCompletion

				message: `${line.substr(index, 10)} should be spelled TypeScript`
			});
		}
	}
	// Send the computed diagnostics to VSCode.
	connection.sendDiagnostics({ uri: textDocument.uri, diagnostics });
}

connection.onDidChangeWatchedFiles((change) => {
	// Monitored files have change in VSCode
	//connection.console.log('We recevied an file change event');
});

//Math.pow(3,1);
// This handler provides the initial list of the completion items.
connection.onCompletion(handleOnCompletion);

function handleOnCompletion(textDocumentPosition: TextDocumentIdentifier) : CompletionItem[]
{
	// The pass parameter contains the position of the text document in 
	// which code complete got requested. For the example we ignore this
	// info and always provide the same completion items.
 
	return [
		{
			label: 'SELECT',
			kind: CompletionItemKind.Keyword,
			data: 0
		},
		{
			label: 'FROM',
开发者ID:babakness,项目名称:vscode-pgsql,代码行数:31,代码来源:server.ts


示例9: calculator

	return [
		{currentFile: 'bindings.cs', labels: ['Given is a test', 'Given is a teest']},
		{currentFile: 'bindings.cs', labels: ['When it is a test']},
		{currentFile: 'bindings.cs', labels: ['Then it must be a test']}
	];
}

connection.onCompletion((textDocumentPosition: TextDocumentIdentifier): CompletionItem[] => {
	
	let specflowExamples =  [
		{
			label: 'Given I have entered <number> into the calculator (from server)',
			kind: CompletionItemKind.Value,
			data: 1
		},
		{
			label: 'When I press add',
			kind: CompletionItemKind.Value,
			data: 2
		},
		{
			label: 'Then the result should be <number> on the screen',
			kind: CompletionItemKind.Value,
			data: 3
		}
	]
	
	return specflowExamples;
});

connection.listen();
开发者ID:pumbaEO,项目名称:vscode-specflow,代码行数:31,代码来源:server.ts



注:本文中的vscode-languageserver.IConnection.onCompletion方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。