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


TypeScript IConnection.onInitialize方法代码示例

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

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

示例1: getWorkspaceUri

 const server = await new Promise<LanguageServer>((resolve, reject) => {
   connection.onInitialize(async(params): Promise<InitializeResult> => {
     // Normalize across the two ways that the workspace may be
     // communicated to us.
     const workspaceUri = getWorkspaceUri(params.rootUri, params.rootPath);
     if (!workspaceUri || workspaceUri.scheme !== 'file') {
       const error = new Error(
           `Got invalid workspaceUri from client: ` +
           `${util.inspect(workspaceUri)}`);
       reject(error);
       throw error;
     }
     const {urlResolver} =
         await ProjectConfig.initializeAnalyzerFromDirectory(
             workspaceUri.fsPath);
     const newServer = new LanguageServer(
         connection,
         workspaceUri,
         params.capabilities,
         urlResolver,
         loggingOptions.logToFile);
     resolve(newServer);
     return {capabilities: newServer.capabilities(params.capabilities)};
   });
 });
开发者ID:Polymer,项目名称:tools,代码行数:25,代码来源:language-server.ts


示例2: hasClientCapability

connection.onInitialize((params: InitializeParams): InitializeResult => {
	let initializationOptions = params.initializationOptions;

	workspacePath = params.rootPath;

	languageModes = getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true });
	documents.onDidClose(e => {
		languageModes.onDocumentRemoved(e.document);
	});
	connection.onShutdown(() => {
		languageModes.dispose();
	});

	function hasClientCapability(...keys: string[]) {
		let c = params.capabilities;
		for (let i = 0; c && i < keys.length; i++) {
			c = c[keys[i]];
		}
		return !!c;
	}

	clientSnippetSupport = hasClientCapability('textDocument', 'completion', 'completionItem', 'snippetSupport');
	clientDynamicRegisterSupport = hasClientCapability('workspace', 'symbol', 'dynamicRegistration');
	scopedSettingsSupport = hasClientCapability('workspace', 'configuration');
	let capabilities: ServerCapabilities & CPServerCapabilities = {
		// Tell the client that the server works in FULL text document sync mode
		textDocumentSync: documents.syncKind,
		completionProvider: clientSnippetSupport ? { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '=', '/', '>'] } : null,
		hoverProvider: true,
		documentHighlightProvider: true,
		documentRangeFormattingProvider: false,
		documentLinkProvider: { resolveProvider: false },
		documentSymbolProvider: true,
		definitionProvider: true,
		signatureHelpProvider: { triggerCharacters: ['('] },
		referencesProvider: true,
		colorProvider: true
	};

	return { capabilities };
});
开发者ID:armanio123,项目名称:vscode,代码行数:41,代码来源:htmlServerMain.ts


示例3: TextDocuments

// Create a simple text document manager. The text document manager
// supports full document sync only
let documents: TextDocuments = new TextDocuments();
// Make the text document manager listen on the connection
// for open, change and close text document events
documents.listen(connection);

// After the server has started the client sends an initialize request. The server receives
// in the passed params the rootPath of the workspace plus the client capabilities. 
let workspaceRoot: string;
connection.onInitialize((params): InitializeResult => {
	workspaceRoot = params.rootPath;
	return {
		capabilities: {
			// Tell the client that the server works in FULL text document sync mode
			textDocumentSync: documents.syncKind,
            
			}
		}
});

// The content of a text document has changed. This event is emitted
// when the text document first opened or when its content has changed.
documents.onDidChangeContent((change) => {
    let diagnostics: Diagnostic[] = [];
    let input = change.document.getText();
    
    try{
        let output = toml.parse(input);
    }catch(e){
        // workaround for typescript limitation
开发者ID:digitaltoad,项目名称:dotfiles,代码行数:31,代码来源:tomlServerMain.ts


示例4: getLanguageModes

// After the server has started the client sends an initilize request. The server receives
// in the passed params the rootPath of the workspace plus the client capabilites
connection.onInitialize((params: InitializeParams): InitializeResult => {
	let initializationOptions = params.initializationOptions;

	workspacePath = params.rootPath;

	languageModes = getLanguageModes(initializationOptions ? initializationOptions.embeddedLanguages : { css: true, javascript: true });
	documents.onDidClose(e => {
		languageModes.getAllModes().forEach(m => m.onDocumentRemoved(e.document));
	});
	connection.onShutdown(() => {
		languageModes.getAllModes().forEach(m => m.dispose());
	});

	return {
		capabilities: {
			// Tell the client that the server works in FULL text document sync mode
			textDocumentSync: documents.syncKind,
			completionProvider: { resolveProvider: true, triggerCharacters: ['.', ':', '<', '"', '=', '/'] },
			hoverProvider: true,
			documentHighlightProvider: true,
			documentRangeFormattingProvider: initializationOptions && initializationOptions['format.enable'],
			documentLinkProvider: true,
			definitionProvider: true,
			signatureHelpProvider: { triggerCharacters: ['('] },
			referencesProvider: true
		}
	};
});

开发者ID:,项目名称:,代码行数:30,代码来源:


示例5: createConnection

 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import {createConnection, Hover, IConnection, InitializeResult, IPCMessageReader, IPCMessageWriter} from 'vscode-languageserver';

const connection: IConnection = createConnection(
    new IPCMessageReader(process), new IPCMessageWriter(process));

connection.onInitialize((params): InitializeResult => {
  return {
    capabilities: {hoverProvider: true}
  }
});

connection.onHover(async(params): Promise<Hover> => {
  return {
    contents: {language: 'javascript', value: 'Hello World'}
  }
});

console.log('Starting Server...');
connection.listen();
开发者ID:legrosbuffle,项目名称:kythe,代码行数:30,代码来源:server.ts


示例6: run

function run() {
    // debounce buffer
    const validationRequestStream = new Rx.ReplaySubject<TextDocument>(1);
    const validationFinishedStream = new Rx.ReplaySubject<{ uri: string; version: number }>(1);
    const triggerUpdateConfig = new Rx.ReplaySubject<void>(1);
    const triggerValidateAll = new Rx.ReplaySubject<void>(1);

    // Create a connection for the server. The connection uses Node's IPC as a transport
    const connection: IConnection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));
    g_connection = connection;
    log('Start');

    // Create a simple text document manager. The text document manager
    // supports full document sync only
    const documents: TextDocuments = new TextDocuments();

    // After the server has started the client sends an initialize request. The server receives
    // in the passed params the rootPath of the workspace plus the client capabilities.
    let workspaceRoot: string | undefined;
    connection.onInitialize((params: InitializeParams, token: CancellationToken): InitializeResult => {
        workspaceRoot = params.rootPath || undefined;
        return {
            capabilities: {
                // Tell the client that the server works in FULL text document sync mode
                textDocumentSync: documents.syncKind,
                codeActionProvider: true
            }
        };
    });

    // The settings have changed. Is sent on server activation as well.
    connection.onDidChangeConfiguration(onConfigChange);

    interface OnChangeParam { settings: Settings; }
    function onConfigChange(change: OnChangeParam) {
        log('onConfigChange');
        Object.assign(vscodeSettings, change.settings || {});
        log(`Enabled: ${vscodeSettings.cSpell && vscodeSettings.cSpell.enabled ? 'True' : 'False'}`);
        triggerUpdateConfig.next(undefined);
    }

    function updateActiveSettings() {
        log('updateActiveSettings');
        CSpell.clearCachedSettings();
        const configPaths = workspaceRoot ? [
            path.join(workspaceRoot, '.vscode', CSpell.defaultSettingsFilename.toLowerCase()),
            path.join(workspaceRoot, '.vscode', CSpell.defaultSettingsFilename),
            path.join(workspaceRoot, CSpell.defaultSettingsFilename.toLowerCase()),
            path.join(workspaceRoot, CSpell.defaultSettingsFilename),
        ] : [];
        const cSpellSettingsFile = CSpell.readSettingsFiles(configPaths);
        const { cSpell = {}, search = {} } = vscodeSettings;
        const { exclude = {} } = search;
        const importPaths = [...configsToImport.keys()].sort();
        const importSettings = CSpell.readSettingsFiles(importPaths);
        const mergedSettings = CSpell.mergeSettings(defaultSettings, importSettings, cSpellSettingsFile, cSpell);
        const { ignorePaths = []} = mergedSettings;
        const globs = defaultExclude.concat(ignorePaths, extractGlobsFromExcludeFilesGlobMap(exclude));
        fnFileExclusionTest = generateExclusionFunctionForUri(globs, workspaceRoot || '');
        Object.assign(activeSettings, mergedSettings);
        activeSettingsNeedUpdating = false;

        triggerValidateAll.next(undefined);
    }

    function getActiveSettings() {
        if (activeSettingsNeedUpdating) {
            updateActiveSettings();
        }
        return activeSettings;
    }

    function registerConfigurationFile(path: string) {
        configsToImport.add(path);
        log(`Load: ${path}`);
        triggerUpdateConfig.next(undefined);
    }

    interface TextDocumentInfo {
        uri?: string;
        languageId?: string;
    }

    // Listen for event messages from the client.
    connection.onNotification('applySettings', onConfigChange);
    connection.onNotification('registerConfigurationFile', registerConfigurationFile);

    connection.onRequest('isSpellCheckEnabled', (params: TextDocumentInfo) => {
        const { uri, languageId } = params;
        return {
            languageEnabled: languageId ? isLanguageEnabled(languageId) : undefined,
            fileEnabled: uri ? !isUriExcluded(uri) : undefined,
        };
    });

    connection.onRequest('getConfigurationForDocument', (params: TextDocumentInfo) => {
        const { uri, languageId } = params;
        const doc = uri && documents.get(uri);
        const docSettings = doc && getSettingsToUseForDocument(doc);
        const settings = activeSettings;
//.........这里部分代码省略.........
开发者ID:AlekSi,项目名称:vscode-spell-checker,代码行数:101,代码来源:server.ts


示例7: createConnection

const getHelpUrl = (section: string): string => {
  return `https://github.com/XVincentX/vscode-apielements/blob/master/TROUBLESHOT.md${section}`;
};

const connection: IConnection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));
const documents: TextDocuments = new TextDocuments();
documents.listen(connection);

let workspaceRoot: string;
connection.onInitialize((params): InitializeResult => {
  workspaceRoot = params.rootPath;

  const capabilities: ServerCapabilities = {
    documentSymbolProvider: true,
    textDocumentSync: documents.syncKind,
  };

  return {
    capabilities,
  } as InitializeResult;

});

documents.onDidChangeContent((change) => {
  debouncedValidateTextDocument(change.document);
});

documents.onDidClose((event) => {
  connection.sendDiagnostics({ diagnostics: [], uri: event.document.uri });
});
开发者ID:XVincentX,项目名称:vscode-apielements,代码行数:30,代码来源:server.ts


示例8: createConnection

let connection: IConnection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));
let documents: TextDocuments = new TextDocuments();
documents.listen(connection);

let workspaceRoot: string;
connection.onInitialize((params): Thenable<InitializeResult | ResponseError<InitializeError>> => {
  workspaceRoot = params.rootPath;

  const capabilities : ServerCapabilities = {
      textDocumentSync: documents.syncKind,
      documentSymbolProvider: true
    }

  return Files.resolveModule(workspaceRoot, 'drafter.js').then((value) => {
    setParser(value, 'Drafter.js');
    return { capabilities: capabilities };
  }, (error) => {
    return Files.resolveModule(workspaceRoot, 'protagonist').then((value) => {
      setParser(value, 'Protagonist');
      return { capabilities: capabilities };
  }, (error) => {
      setParser(require('drafter.js'), 'Ext Drafter.js');
      return { capabilities: capabilities };
    });
  });
});

documents.onDidChangeContent((change) => {
  validateTextDocument(change.document);
});
开发者ID:smizell,项目名称:vscode-apielements,代码行数:30,代码来源:server.ts


示例9: createConnection

import { rebuildTreeSitter } from './util/rebuilder';

const connection: IConnection = createConnection(ProposedFeatures.all);
let server: ILanguageServer;

connection.onInitialize(async (params: InitializeParams) => {
	connection.console.info('Initializing Ruby language server...');

	connection.console.info('Rebuilding tree-sitter for local Electron version');
	const rebuildResult: [void | Error, void | Error] = await rebuildTreeSitter();
	for (const result of rebuildResult) {
		if (result) {
			connection.console.error('Rebuild failed!');
			connection.console.error(result.toString());

			return null;
		}
	}
	connection.console.info('Rebuild succeeded!');

	const { Server } = await import('./Server');
	server = new Server(connection, params);
	server.registerInitializeProviders();

	return server.capabilities;
});

connection.onInitialized(() => {
	server.registerInitializedProviders();
});
开发者ID:rubyide,项目名称:vscode-ruby,代码行数:30,代码来源:index.ts


示例10: createConnection

import {
    createConnection,
    IConnection,
    IPCMessageReader,
    IPCMessageWriter,
    DidChangeConfigurationNotification
} from 'vscode-languageserver';

import { LocalSyncFs } from './local-sync-fs';
import { init } from './server-utils';
import { initializeResult } from '../view';

const connection: IConnection = createConnection(new IPCMessageReader(process), new IPCMessageWriter(process));

connection.listen();
connection.onInitialize(params => {
    const rootPath = params.rootPath || '';

    init(new LocalSyncFs(''), connection, rootPath);

    return initializeResult;
});

connection.onInitialized(() => {
    connection.client.register(DidChangeConfigurationNotification.type, undefined);
});
开发者ID:wix,项目名称:stylable-intelligence,代码行数:26,代码来源:server.ts



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